Class: OData::EnumType

Inherits:
Type
  • Object
show all
Defined in:
lib/odata/types/enum_type.rb

Instance Attribute Summary collapse

Attributes inherited from Type

#name

Instance Method Summary collapse

Methods inherited from Type

#collection?

Constructor Details

#initialize(options = {}) ⇒ EnumType

Returns a new instance of EnumType


5
6
7
8
# File 'lib/odata/types/enum_type.rb', line 5

def initialize(options={})
  super
  @members = options[:members]
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members


3
4
5
# File 'lib/odata/types/enum_type.rb', line 3

def members
  @members
end

Instance Method Details

#coerce(value) ⇒ Object


18
19
20
21
22
23
24
25
# File 'lib/odata/types/enum_type.rb', line 18

def coerce(value)
  if value && value.is_a?(Integer)
    member = @members.find { |m| m[:value] == value }
    member && member[:name]
  else
    super
  end
end

#typeObject


14
15
16
# File 'lib/odata/types/enum_type.rb', line 14

def type
  name
end

#valid_value?(value) ⇒ Boolean

Returns:

  • (Boolean)

10
11
12
# File 'lib/odata/types/enum_type.rb', line 10

def valid_value?(value)
  member_names.include?(value) || member_values.include?(value)
end