Class: WowzaRest::Data::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wowza_rest/data/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/wowza_rest/data/base.rb', line 4

def initialize(attrs = {})
  setup_attributes(attrs)
end

Instance Method Details

#define_attribute_getter(attr_name) ⇒ Object



16
17
18
19
20
# File 'lib/wowza_rest/data/base.rb', line 16

def define_attribute_getter(attr_name)
  define_singleton_method(attr_name.to_s) do
    instance_variable_get("@#{attr_name}")
  end
end

#define_attribute_setter(attr_name) ⇒ Object



22
23
24
25
26
# File 'lib/wowza_rest/data/base.rb', line 22

def define_attribute_setter(attr_name)
  define_singleton_method("#{attr_name}=") do |value|
    instance_variable_set("@#{attr_name}", value)
  end
end

#map_array_objects(arr, klass) ⇒ Object



28
29
30
# File 'lib/wowza_rest/data/base.rb', line 28

def map_array_objects(arr, klass)
  arr.map { |obj| klass.new(obj) }
end

#setup_attributes(attrs) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/wowza_rest/data/base.rb', line 8

def setup_attributes(attrs)
  attrs.each do |k, v|
    define_attribute_getter(k.underscore)
    define_attribute_setter(k.underscore)
    instance_variable_set("@#{k.underscore}", v)
  end
end