class FrOData::Schema::EnumType

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

Public Class Methods

new(type_definition, schema) click to toggle source

Creates a new EnumType based on the supplied options. @param type_xml [Nokogiri::XML::Element] @param service [FrOData::Service] @return [self]

# File lib/frodata/schema/enum_type.rb, line 10
def initialize(type_definition, schema)
  @type_definition = type_definition
  @schema          = schema
end

Public Instance Methods

[](member_name) click to toggle source

Returns the value of the requested member. @param member_name [to_s] @return [*]

# File lib/frodata/schema/enum_type.rb, line 66
def [](member_name)
  members.invert[member_name.to_s]
end
is_flags?() click to toggle source

Whether this EnumType supports setting multiple values. @return [Boolean]

# File lib/frodata/schema/enum_type.rb, line 29
def is_flags?
  options['IsFlags'] == 'true'
end
members() click to toggle source

Returns the members of this EnumType and their values. @return [Hash]

# File lib/frodata/schema/enum_type.rb, line 47
def members
  @members ||= collect_members
end
name() click to toggle source

The name of the EnumType @return [String]

# File lib/frodata/schema/enum_type.rb, line 17
def name
  options['Name']
end
namespace() click to toggle source

Returns the namespace this EnumType belongs to. @return [String]

# File lib/frodata/schema/enum_type.rb, line 41
def namespace
  @namespace ||= service.namespace
end
property_class() click to toggle source

Returns the property class that implements this `EnumType`. @return [Class < FrOData::Properties::Enum]

# File lib/frodata/schema/enum_type.rb, line 53
def property_class
  @property_class ||= lambda { |type, members, is_flags|
    klass = Class.new ::FrOData::Properties::Enum
    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() click to toggle source

Returns the namespaced type for the EnumType. @return [String]

# File lib/frodata/schema/enum_type.rb, line 23
def type
  "#{namespace}.#{name}"
end
underlying_type() click to toggle source

The underlying type of this EnumType. @return [String]

# File lib/frodata/schema/enum_type.rb, line 35
def underlying_type
  options['UnderlyingType'] || 'Edm.Int32'
end

Private Instance Methods

collect_members() click to toggle source
# File lib/frodata/schema/enum_type.rb, line 86
def collect_members
  Hash[type_definition.xpath('./Member').map.with_index do |member_xml, index|
    member_name  = member_xml.attributes['Name'].value
    member_value = member_xml.attributes['Value'].andand.value.andand.to_i
    [member_value || index, member_name]
  end]
end
options() click to toggle source
# File lib/frodata/schema/enum_type.rb, line 80
def options
  @options = type_definition.attributes.map do |name, attr|
    [name, attr.value]
  end.to_h
end
service() click to toggle source
# File lib/frodata/schema/enum_type.rb, line 72
def service
  @schema.service
end
type_definition() click to toggle source
# File lib/frodata/schema/enum_type.rb, line 76
def type_definition
  @type_definition
end