Class: Kamakura::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, key: nil, **options) ⇒ Attribute

Returns a new instance of Attribute.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kamakura/attribute.rb', line 8

def initialize(name, type, key: nil, **options)
  @name = name.to_sym
  @key = key ? key.to_sym : @name
  @options = options

  if type.is_a?(Array)
    if value_type = Kamakura.lookup_value_type(type[0])
      @type = CollectionType.new(value_type)
    else
      @type = CollectionType.new(type[0])
    end
  elsif value_type = Kamakura.lookup_value_type(type)
    @type = value_type
  else
    @type = type
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/kamakura/attribute.rb', line 6

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/kamakura/attribute.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/kamakura/attribute.rb', line 6

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/kamakura/attribute.rb', line 6

def type
  @type
end

Instance Method Details

#parse(value) ⇒ Object



26
27
28
# File 'lib/kamakura/attribute.rb', line 26

def parse(value)
  @type.parse(value, @options)
end