Class: OData4::EnumType
- Inherits:
-
Object
- Object
- OData4::EnumType
- 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
-
#[](member_name) ⇒ *
Returns the value of the requested member.
-
#initialize(type_definition, schema) ⇒ self
constructor
Creates a new EnumType based on the supplied options.
-
#is_flags? ⇒ Boolean
Whether this EnumType supports setting multiple values.
-
#members ⇒ Hash
Returns the members of this EnumType and their values.
-
#name ⇒ String
The name of the EnumType.
-
#namespace ⇒ String
Returns the namespace this EnumType belongs to.
-
#property_class ⇒ Class < OData4::EnumType::Property]
Returns the property class that implements this ‘EnumType`.
-
#type ⇒ String
Returns the namespaced type for the EnumType.
-
#underlying_type ⇒ String
The underlying type of this EnumType.
Constructor Details
#initialize(type_definition, schema) ⇒ self
Creates a new EnumType based on the supplied options.
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.
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.
30 31 32 |
# File 'lib/odata4/enum_type.rb', line 30 def is_flags? ['IsFlags'] == 'true' end |
#members ⇒ Hash
Returns the members of this EnumType and their values.
48 49 50 |
# File 'lib/odata4/enum_type.rb', line 48 def members @members ||= collect_members end |
#name ⇒ String
The name of the EnumType
18 19 20 |
# File 'lib/odata4/enum_type.rb', line 18 def name ['Name'] end |
#namespace ⇒ String
Returns the namespace this EnumType belongs to.
42 43 44 |
# File 'lib/odata4/enum_type.rb', line 42 def namespace @namespace ||= service.namespace end |
#property_class ⇒ Class < OData4::EnumType::Property]
Returns the property class that implements this ‘EnumType`.
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 |
#type ⇒ String
Returns the namespaced type for the EnumType.
24 25 26 |
# File 'lib/odata4/enum_type.rb', line 24 def type "#{namespace}.#{name}" end |
#underlying_type ⇒ String
The underlying type of this EnumType.
36 37 38 |
# File 'lib/odata4/enum_type.rb', line 36 def ['UnderlyingType'] || 'Edm.Int32' end |