Class: JetSet::Row
- Inherits:
-
Object
- Object
- JetSet::Row
- Defined in:
- lib/jet_set/row.rb
Overview
A container for fields/references extraction logic
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#attributes_hash ⇒ Object
readonly
Returns the value of attribute attributes_hash.
-
#reference_names ⇒ Object
readonly
Returns the value of attribute reference_names.
Instance Method Summary collapse
-
#initialize(row_hash, entity_fields, prefix) ⇒ Row
constructor
A new instance of Row.
Constructor Details
#initialize(row_hash, entity_fields, prefix) ⇒ Row
Returns a new instance of Row.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jet_set/row.rb', line 6 def initialize(row_hash, entity_fields, prefix) keys = row_hash.keys.map {|key| key.to_s} @attributes = keys.select {|key| key.to_s.start_with? prefix + '__'} .select {|key| entity_fields.include? key.sub(prefix + '__', '')} .map {|key| {field: key.sub(prefix + '__', ''), value: row_hash[key.to_sym]}} @attributes_hash = {} @attributes.each do |attr| @attributes_hash[attr[:field].to_sym] = attr[:value] end @reference_names = keys.select {|key| !key.start_with?(prefix) && key.include?('__')} .map {|key| key.split('__')[0]} .uniq end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/jet_set/row.rb', line 4 def attributes @attributes end |
#attributes_hash ⇒ Object (readonly)
Returns the value of attribute attributes_hash.
4 5 6 |
# File 'lib/jet_set/row.rb', line 4 def attributes_hash @attributes_hash end |
#reference_names ⇒ Object (readonly)
Returns the value of attribute reference_names.
4 5 6 |
# File 'lib/jet_set/row.rb', line 4 def reference_names @reference_names end |