Class: Basuco::Property
- Inherits:
-
Object
- Object
- Basuco::Property
- Defined in:
- lib/basuco/property.rb
Constant Summary collapse
- VALUE_TYPES =
include Extlib::Assertions
%w{ /type/id /type/int /type/float /type/boolean /type/text /type/rawstring /type/uri /type/datetime /type/key }
Instance Method Summary collapse
-
#expected_type ⇒ Object
type, which attribute values of that property are expected to have.
-
#id ⇒ Object
property id.
-
#initialize(data, type) ⇒ Property
constructor
initializes a resource by json result.
- #inspect ⇒ Object
-
#master_property ⇒ Object
master property, which represent an outgoing link (or primitive value).
-
#name ⇒ Object
property name.
-
#object_type? ⇒ Boolean
returns true if the property is an object type.
-
#reverse_property ⇒ Object
reverse property, which represent incoming links.
- #to_s ⇒ Object
-
#type ⇒ Object
returns the type of which the property is a part of every property always has exactly one type.
-
#unique? ⇒ Boolean
returns true if the property is unique.
-
#value_type? ⇒ Boolean
returns true if the property is a value type.
Constructor Details
#initialize(data, type) ⇒ Property
initializes a resource by json result
19 20 21 22 23 |
# File 'lib/basuco/property.rb', line 19 def initialize(data, type) # assert_kind_of 'data', data, Hash # assert_kind_of 'type', type, Basuco::Type @data, @type = data, type end |
Instance Method Details
#expected_type ⇒ Object
type, which attribute values of that property are expected to have
87 88 89 |
# File 'lib/basuco/property.rb', line 87 def expected_type @data["expected_type"] end |
#id ⇒ Object
property id
27 28 29 |
# File 'lib/basuco/property.rb', line 27 def id @data["id"] end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/basuco/property.rb', line 43 def inspect result = "#<Property id=\"#{id}\" expected_type=\"#{expected_type || "nil"}\" unique=\"#{unique?}\" object_type=\"#{object_type?}\">" end |
#master_property ⇒ Object
master property, which represent an outgoing link (or primitive value)
63 64 65 |
# File 'lib/basuco/property.rb', line 63 def master_property @data["master_property"] end |
#name ⇒ Object
property name
33 34 35 |
# File 'lib/basuco/property.rb', line 33 def name @data["name"] end |
#object_type? ⇒ Boolean
returns true if the property is an object type
75 76 77 |
# File 'lib/basuco/property.rb', line 75 def object_type? !value_type? end |
#reverse_property ⇒ Object
reverse property, which represent incoming links
57 58 59 |
# File 'lib/basuco/property.rb', line 57 def reverse_property @data["reverse_property"] end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/basuco/property.rb', line 38 def to_s name || id || "" end |
#type ⇒ Object
returns the type of which the property is a part of every property always has exactly one type. that’s why /type/property/schema is a unique property
51 52 53 |
# File 'lib/basuco/property.rb', line 51 def type @type end |
#unique? ⇒ Boolean
returns true if the property is unique
69 70 71 |
# File 'lib/basuco/property.rb', line 69 def unique? return @data["unique"]==true end |
#value_type? ⇒ Boolean
returns true if the property is a value type
81 82 83 |
# File 'lib/basuco/property.rb', line 81 def value_type? VALUE_TYPES.include?(expected_type) end |