Class: Acorn::DataProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/acorn/data_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ DataProcessor

Returns a new instance of DataProcessor.



4
5
6
7
8
# File 'lib/acorn/data_processor.rb', line 4

def initialize data
  self.data = data
  self.data.attr_names.map! {|x| x.to_s}
  self.data.seed_names.map! {|x| x.to_s}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/acorn/data_processor.rb', line 3

def data
  @data
end

Instance Method Details

#processObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/acorn/data_processor.rb', line 9

def process
  data = self.data
  DataValidator.new(data).validate!

  seed_grabber = SeedGrabber.new data.dir_name, data.seed_names
  seeds = seed_grabber.grab

  friendly = ARFriendly.new(data.attr_names, seeds).to_friendly
  friendly.each do |f|
    obj = data.ar_class.new
    f.each do |k,v|
      obj.send k.to_s + '=', v
    end
    obj.save!
  end
end