Class: JetSet::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/jet_set/row.rb

Overview

A container for fields/references extraction logic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row_hash, entity_fields, prefix) ⇒ Row



6
7
8
9
10
11
12
13
14
15
16
# 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]}}

  @reference_names = keys.select {|key| !key.start_with?(prefix) && key.include?('__')}
    .map {|key| key.split('__')[0]}
    .uniq
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/jet_set/row.rb', line 4

def attributes
  @attributes
end

#reference_namesObject (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