Class: BrickHouse::DataSetObject

Inherits:
Object
  • Object
show all
Defined in:
app/models/brick_house/data_set_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_array) ⇒ DataSetObject

Returns a new instance of DataSetObject.



4
5
6
7
8
9
10
# File 'app/models/brick_house/data_set_object.rb', line 4

def initialize(hash_or_array)
  if hash_or_array.is_a?(Array)
    @result = hash_or_array.map { |hash| process_hash_to_object(hash) }
  else
    @result = process_hash_to_object(hash_or_array)
  end
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



2
3
4
# File 'app/models/brick_house/data_set_object.rb', line 2

def results
  @results
end

Instance Method Details

#process_hash_to_object(hash) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/models/brick_house/data_set_object.rb', line 12

def process_hash_to_object(hash)
  hash.each do |k,v|
    k = k.gsub('(','_').gsub(')','_')
    self.instance_variable_set("@#{k}",v)
    self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
    self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}",v)})
  end
  return hash
end