Sha256: f73377bf7a9c03b2513df6a9dbfe0dd2b18c116ad8ffa86acaf987822faea925
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
module OData4 class EnumType # Abstract base class for OData4 EnumTypes # @see [OData4::EnumType] class Property < OData4::Property # Returns the property value, properly typecast # @return [String, nil] def value if @value.nil? && allows_nil? nil else @value end end # Sets the property value # @params new_value [String] def value=(new_value) parsed_value = validate(new_value) @value = is_flags? ? parsed_value : parsed_value.first end # Value to be used in URLs. # @return [String] def url_value "#{type}'#{@value}'" end private def members raise NotImplementedError, 'Subclass must override' end def validate(value) return [] if value.nil? && allows_nil? values = parse_value(value) if values.length > 1 && !is_flags? raise ArgumentError, 'Multiple values are not allowed for this property' end values.map do |value| if members.keys.include?(value) members[value] elsif members.values.include?(value) value else raise ArgumentError, "Property '#{name}': Value must be one of #{members.to_a}, but was: '#{value}'" if strict? end end.compact end def parse_value(value) return nil if value.nil? value.to_s.split(',').map(&:strip).map do |val| val =~ /^[0-9]+$/ ? val.to_i : val end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
odata4-0.7.0 | lib/odata4/enum_type/property.rb |