Class: Acorn::ARFriendly
- Inherits:
-
Object
- Object
- Acorn::ARFriendly
- Defined in:
- lib/acorn/ar_friendly.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
Returns the value of attribute column_names.
-
#seeds ⇒ Object
Returns the value of attribute seeds.
Instance Method Summary collapse
-
#initialize(column_names, seeds) ⇒ ARFriendly
constructor
takes something like [:col1, :col2] [[:a,:b],] to [=> :a, :col2 => :c, => :b, :col2 => :d].
- #to_friendly ⇒ Object
Constructor Details
#initialize(column_names, seeds) ⇒ ARFriendly
takes something like [:col1, :col2] [[:a,:b],] to [=> :a, :col2 => :c, => :b, :col2 => :d]
6 7 8 9 |
# File 'lib/acorn/ar_friendly.rb', line 6 def initialize column_names, seeds self.column_names = column_names self.seeds = seeds end |
Instance Attribute Details
#column_names ⇒ Object
Returns the value of attribute column_names.
3 4 5 |
# File 'lib/acorn/ar_friendly.rb', line 3 def column_names @column_names end |
#seeds ⇒ Object
Returns the value of attribute seeds.
3 4 5 |
# File 'lib/acorn/ar_friendly.rb', line 3 def seeds @seeds end |
Instance Method Details
#to_friendly ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/acorn/ar_friendly.rb', line 10 def to_friendly #seeds is like [[:a,:b,:c],[:d,:e,:f]] first = self.seeds[0] rest = self.seeds.drop 1 #zipped is like [[:a,:d],[:b,:e],[:c,:f]] zipped = first.zip(*rest) zipped.map do |z| hash = {} self.column_names.zip(z).each do |zz| hash[zz[0].to_sym] = zz[1] end hash end end |