Class: OData4::EnumType

Inherits:
Object
  • Object
show all
Defined in:
lib/odata4/enum_type.rb,
lib/odata4/enum_type/property.rb

Overview

Enumeration types are nominal types that represent a series of related values. Enumeration types expose these related values as members of the enumeration.

Defined Under Namespace

Classes: Property

Instance Method Summary collapse

Constructor Details

#initialize(type_definition, schema) ⇒ self

Creates a new EnumType based on the supplied options.

Parameters:



11
12
13
14
# File 'lib/odata4/enum_type.rb', line 11

def initialize(type_definition, schema)
  @type_definition = type_definition
  @schema          = schema
end

Instance Method Details

#[](member_name) ⇒ *

Returns the value of the requested member.

Parameters:

  • member_name (to_s)

Returns:

  • (*)


67
68
69
# File 'lib/odata4/enum_type.rb', line 67

def [](member_name)
  members.invert[member_name.to_s]
end

#is_flags?Boolean

Whether this EnumType supports setting multiple values.

Returns:

  • (Boolean)


30
31
32
# File 'lib/odata4/enum_type.rb', line 30

def is_flags?
  options['IsFlags'] == 'true'
end

#membersHash

Returns the members of this EnumType and their values.

Returns:

  • (Hash)


48
49
50
# File 'lib/odata4/enum_type.rb', line 48

def members
  @members ||= collect_members
end

#nameString

The name of the EnumType

Returns:

  • (String)


18
19
20
# File 'lib/odata4/enum_type.rb', line 18

def name
  options['Name']
end

#namespaceString

Returns the namespace this EnumType belongs to.

Returns:

  • (String)


42
43
44
# File 'lib/odata4/enum_type.rb', line 42

def namespace
  @namespace ||= service.namespace
end

#property_classClass < OData4::EnumType::Property]

Returns the property class that implements this ‘EnumType`.

Returns:



54
55
56
57
58
59
60
61
62
# File 'lib/odata4/enum_type.rb', line 54

def property_class
  @property_class ||= lambda { |type, members, is_flags|
    klass = Class.new ::OData4::EnumType::Property
    klass.send(:define_method, :type) { type }
    klass.send(:define_method, :members) { members }
    klass.send(:define_method, :is_flags?) { is_flags }
    klass
  }.call(type, members, is_flags?)
end

#typeString

Returns the namespaced type for the EnumType.

Returns:

  • (String)


24
25
26
# File 'lib/odata4/enum_type.rb', line 24

def type
  "#{namespace}.#{name}"
end

#underlying_typeString

The underlying type of this EnumType.

Returns:

  • (String)


36
37
38
# File 'lib/odata4/enum_type.rb', line 36

def underlying_type
  options['UnderlyingType'] || 'Edm.Int32'
end