Class: Ken::View

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

Instance Method Summary collapse

Constructor Details

#initialize(subject, type) ⇒ View

initializes a subject (resource or topic) by json result



9
10
11
12
# File 'lib/ken/view.rb', line 9

def initialize(subject, type)
  assert_kind_of 'type', type, Ken::Type
  @subject, @type = subject, type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object

delegate to attribute



50
51
52
# File 'lib/ken/view.rb', line 50

def method_missing sym
  attribute(sym.to_s)
end

Instance Method Details

#attribute(name) ⇒ Object

search for an attribute by name and return it



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

def attribute(name)
  attributes.each { |a| return a if a.property.id =~ /\/#{name}$/ }
  nil
end

#attributesObject

returns attributes which are member of the view’s type



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

def attributes
  @subject.attributes.select { |a| a.property.type == @type}
end

#inspectObject



26
27
28
# File 'lib/ken/view.rb', line 26

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

#propertiesObject

returns properties which are member of the view’s type



45
46
47
# File 'lib/ken/view.rb', line 45

def properties
  @subject.properties.select { |p| p.type == @type}
end

#to_sObject



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

def to_s
  @type.to_s
end

#typeObject

return correspondent type



21
22
23
# File 'lib/ken/view.rb', line 21

def type
  @type
end