Module: Nilavu::MegamAttributes

Constant Summary collapse

ATTRIBUTES =
[]
KEY =
'key'.freeze
VALUE =
'value'.freeze

Instance Method Summary collapse

Instance Method Details

#attributesObject



9
10
11
# File 'lib/megam/mixins/megam_attributes.rb', line 9

def attributes
    NotImplementedError
end

#initialize(control_data = {}) ⇒ Object



13
14
15
# File 'lib/megam/mixins/megam_attributes.rb', line 13

def initialize(control_data = {})
    set_attributes(control_data)
end

#set_attributes(control_data) ⇒ Object



17
18
19
# File 'lib/megam/mixins/megam_attributes.rb', line 17

def set_attributes(control_data)
    attributes.each { |a| instance_variable_set("@#{a}", control_data[a]) unless control_data[a].nil? }
end

#to_hashObject



21
22
23
24
25
26
27
28
# File 'lib/megam/mixins/megam_attributes.rb', line 21

def to_hash
    h = attributes.reduce([]) do |res, key|
        val = instance_variable_get("@#{key}".to_sym)
        res << { KEY => key.to_s, VALUE => val } unless val.nil?
        res
    end
    h
end