Class: OData::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/odata/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Property


9
10
11
12
13
# File 'lib/odata/property.rb', line 9

def initialize(options = {})
  @name     = options[:name]
  @nullable = options[:nullable]
  @type     = options[:type]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/odata/property.rb', line 5

def name
  @name
end

#nullableObject (readonly)

Returns the value of attribute nullable


6
7
8
# File 'lib/odata/property.rb', line 6

def nullable
  @nullable
end

#typeObject (readonly)

Returns the value of attribute type


7
8
9
# File 'lib/odata/property.rb', line 7

def type
  @type
end

Instance Method Details

#coerce_to_type(value) ⇒ Object


19
20
21
22
# File 'lib/odata/property.rb', line 19

def coerce_to_type(value)
  return nil if value.nil?
  type.coerce(value)
end

#collection?Boolean


15
16
17
# File 'lib/odata/property.rb', line 15

def collection?
  OData::CollectionType === type
end

#collection_type_match?(value) ⇒ Boolean


24
25
26
27
# File 'lib/odata/property.rb', line 24

def collection_type_match?(value)
  collection = type
  collection.valid_value?(value)
end

#nullable_match?(value) ⇒ Boolean


33
34
35
# File 'lib/odata/property.rb', line 33

def nullable_match?(value)
  nullable || !value.nil?
end

#type_match?(value) ⇒ Boolean


29
30
31
# File 'lib/odata/property.rb', line 29

def type_match?(value)
  type.valid_value?(value) || (value.nil? && nullable)
end