Class: Ken::Attribute

Inherits:
Object
  • Object
show all
Includes:
Extlib::Assertions
Defined in:
lib/ken/attribute.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Attribute) initialize(data, property)

initializes a resource by json result



7
8
9
10
11
# File 'lib/ken/attribute.rb', line 7

def initialize(data, property)
  assert_kind_of 'data', data, Array
  assert_kind_of 'property', property, Ken::Property
  @data, @property = data, property
end

Instance Attribute Details

- (Object) property (readonly)

Returns the value of attribute property



4
5
6
# File 'lib/ken/attribute.rb', line 4

def property
  @property
end

Class Method Details

+ (Object) create(data, property)

factory method for creating an attribute instance



15
16
17
# File 'lib/ken/attribute.rb', line 15

def self.create(data, property)
  Ken::Attribute.new(data, property)
end

Instance Method Details

- (Object) expected_type

type, which attribute values of that property are expected to have



57
58
59
# File 'lib/ken/attribute.rb', line 57

def expected_type
  @property.expected_type
end

- (Object) inspect



25
26
27
# File 'lib/ken/attribute.rb', line 25

def inspect
  result = "#<Attribute property=\"#{property.id || "nil"}\">"
end

- (Boolean) object_type?

object type properties always link to resources



44
45
46
# File 'lib/ken/attribute.rb', line 44

def object_type?
  @property.object_type?
end

- (Object) to_s



20
21
22
# File 'lib/ken/attribute.rb', line 20

def to_s
  subject.to_s
end

- (Boolean) unique?

unique properties can have at least one value



38
39
40
# File 'lib/ken/attribute.rb', line 38

def unique?
  @property.unique?
end

- (Boolean) value_type?

returns true if the property is a value type value type properties refer to simple values like /type/text



51
52
53
# File 'lib/ken/attribute.rb', line 51

def value_type?
  @property.value_type?
end

- (Object) values

returns a collection of values in case of a unique property the array holds just one value



32
33
34
# File 'lib/ken/attribute.rb', line 32

def values
  subject
end