Class: Ken::View

Inherits:
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_get



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

def method_missing sym
  attribute_get(sym.to_s)
end

Instance Method Details

#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



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

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