Sha256: 7ca13c4ad870dd0016ad325ba44b5cef9887cbc849aee442c509320dfc21b432

Contents?: true

Size: 674 Bytes

Versions: 3

Compression:

Stored size: 674 Bytes

Contents

module OData
  class EnumType < Type
    attr_reader :members

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

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

    def type
      name
    end

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

    private

    def member_names
      members.map { |m| m[:name] }
    end

    def member_values
      members.map { |m| m[:value] }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
microsoft_graph-0.1.3 lib/odata/types/enum_type.rb
microsoft_graph-0.1.1 lib/odata/types/enum_type.rb
microsoft_graph-0.1.0 lib/odata/types/enum_type.rb