Class: Basuco::Property

Inherits:
Object
  • Object
show all
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

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_typeObject

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

#idObject

property id



27
28
29
# File 'lib/basuco/property.rb', line 27

def id
  @data["id"]
end

#inspectObject



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_propertyObject

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

#nameObject

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

Returns:

  • (Boolean)


75
76
77
# File 'lib/basuco/property.rb', line 75

def object_type?
  !value_type?
end

#reverse_propertyObject

reverse property, which represent incoming links



57
58
59
# File 'lib/basuco/property.rb', line 57

def reverse_property
  @data["reverse_property"]
end

#to_sObject



38
39
40
# File 'lib/basuco/property.rb', line 38

def to_s
  name || id || ""
end

#typeObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


81
82
83
# File 'lib/basuco/property.rb', line 81

def value_type?
  VALUE_TYPES.include?(expected_type)
end