Class: ActiveApi::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/active_api/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Field

Returns a new instance of Field.



5
6
7
8
9
10
11
12
# File 'lib/active_api/field.rb', line 5

def initialize(options = {})
  @type         = options[:type]
  @name         = options[:name]
  @klass        = options[:klass]
  @value        = options[:value]
  @choice       = options[:choice]
  @field_type   = options[:field_type] || :element
end

Instance Attribute Details

#choiceObject (readonly)

Returns the value of attribute choice.



3
4
5
# File 'lib/active_api/field.rb', line 3

def choice
  @choice
end

#field_typeObject (readonly)

Returns the value of attribute field_type.



3
4
5
# File 'lib/active_api/field.rb', line 3

def field_type
  @field_type
end

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/active_api/field.rb', line 3

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/active_api/field.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/active_api/field.rb', line 3

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/active_api/field.rb', line 3

def value
  @value
end

Instance Method Details

#name_for(object) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/active_api/field.rb', line 14

def name_for(object)
  if choice
    value = object.send(name)
    return nil if value.nil?
    return choice[value.class.to_s]
  else
    name
  end
end