Class: AxTrack::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/ax_track/object.rb

Direct Known Subclasses

Asset, Tracker, Tracker::GPSPosition

Instance Method Summary collapse

Constructor Details

#initialize(json_response) ⇒ Object

Returns a new instance of Object.



6
7
8
9
10
11
12
13
# File 'lib/ax_track/object.rb', line 6

def initialize(json_response)
  # for each key create an own instance variable with a getter
  json_response.each do |key, value|
    instance_variable_set "@#{key}", value
  end

  create_getters
end

Instance Method Details

#create_getters(required_getter_methods = instance_variables.map { |attr_name| attr_name[1..-1 ]}) ⇒ Object

pass in an array for getters which should be generated. if nothing is passed in, it will create an instance variable for all instance variables.



17
18
19
20
21
# File 'lib/ax_track/object.rb', line 17

def create_getters(required_getter_methods = instance_variables.map { |attr_name| attr_name[1..-1 ]})
  required_getter_methods.each do |attr|
    singleton_class.send :attr_reader, attr unless self.respond_to? attr
  end
end