Class: Oym::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/oym/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, klass, array) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
11
# File 'lib/oym/attribute.rb', line 7

def initialize(name, klass, array)
  @name = name
  @klass = klass
  @array = array
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



5
6
7
# File 'lib/oym/attribute.rb', line 5

def array
  @array
end

#klassObject

Returns the value of attribute klass.



4
5
6
# File 'lib/oym/attribute.rb', line 4

def klass
  @klass
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/oym/attribute.rb', line 3

def name
  @name
end

Instance Method Details

#keyObject



13
14
15
# File 'lib/oym/attribute.rb', line 13

def key
  "#{@name}="
end

#value_from(data) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/oym/attribute.rb', line 17

def value_from(data)
  raw = data[name.to_s]
  return raw unless klass
  unless klass.respond_to?(:from_data)
    raise "#{klass} is specified as Oym::Attribute's klass, but #{klass} does not respond to from_data"
  end
  array ? raw.map { |e| klass.from_data(e) } : klass.from_data(raw)
end