lib/nrser/props/instance_methods.rb
# Create a "data" representation suitable for transport, storage, etc.
# 
# The result is meant to consist of only basic data types and structures -
# strings, numbers, arrays, hashes, datetimes, etc... though it depends on
# any custom objects it encounters correctly responding to `#to_data` for
# this to happen (as is implemented from classes that mix in Props here).
# 
# Prop names are converted to strings (from symbols) since though YAML
# supports symbol values, they have poor portability across languages,
# and they mean the same thing in this situation.
# 
# @param [Boolean] only_own
#   When `true`, don't include parent properties.
# 
# @param [Boolean] only_primary
#   When `true`, don't include sourced properties.
# 
# @param [Boolean] add_class
#   Add a special key with the class' name as the value.
# 
# @param [String] class_key
#   Name for special class key.
# 
# @return [Hash<String, *>]
#   Map of property names as strings to their "data" value, plus the special
#   class identifier key and value, if requested.
# 
Create a "data" representation suitable for transport, storage, etc.
The result is meant to consist of only basic data types and structures
strings, numbers, arrays, hashes, datetimes, etc... though it depends on
any custom objects it encounters correctly responding to `#to_data` for
this to happen (as is implemented from classes that mix in Props here).

Prop names are converted to strings (from symbols) since though YAML
supports symbol values, they have poor portability across languages,
and they mean the same thing in this situation.
Create a " data " representation suitable for transport storage etc . The result is meant to consist of only basic data types and structures strings numbers arrays hashes datetimes etc ... though it depends on any custom objects it encounters correctly responding to ` #to_data ` for this to happen ( as is implemented from classes that mix in Props here ) . Prop names are converted to strings ( from symbols ) since though YAML supports symbol values they have poor portability across languages and they mean the same thing in this situation .
def to_data only_own: false,
              only_primary: false,
              add_class: true,
              class_key: NRSER::Props::DEFAULT_CLASS_KEY,
              compact: true
    hash = self.class.props(only_own: only_own, only_primary: only_primary).
      map { |name, prop|
        [name.to_s, prop.to_data(self)]
      }.
      to_h
    hash.compact! if compact
    hash[class_key] = self.class.safe_name if add_class
    hash
  end
def to_data only_own : false , only_primary : false , add_class : true , class_key : NRSER :: Props :: DEFAULT_CLASS_KEY , compact : true hash = self . class . props ( only_own : only_own , only_primary : only_primary ) . map { | name , prop | [ name . to_s , prop . to_data ( self ) ] } . to_h hash . compact! if compact hash [ class_key ] = self . class . safe_name if add_class hash end
Create a "data" representation suitable for transport, storage, etc.
Create a " data " representation suitable for transport storage etc .
Map of property names as strings to their "data" value, plus the special class identifier key and value, if requested.
Map of property names as strings to their " data " value plus the special class identifier key and value if requested .
Hash<String, *>
only_own
<not_specific>
only_primary
<not_specific>
add_class
<not_specific>
class_key
<not_specific>
compact
<not_specific>
<not_specific>
class_key Name for special class key.
class_key Name for special class key .