Class: Ken::View

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

Instance Method Summary collapse

Constructor Details

#initialize(resource, type) ⇒ View

initializes a resource by json result



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object

delegate to attribute



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

def method_missing sym
  attribute(sym.to_s)
end

Instance Method Details

#attribute(name) ⇒ Object

search for an attribute by name and return it



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

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



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

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

#inspectObject



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

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

#propertiesObject

returns properties which are member of the view’s type



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

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

#to_sObject



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

def to_s
  @type.to_s
end

#typeObject

return correspondent type



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

def type
  @type
end