Class: Ken::View
Instance Method Summary collapse
-
#attribute(name) ⇒ Object
search for an attribute by name and return it.
-
#attributes ⇒ Object
returns attributes which are member of the view’s type.
-
#initialize(resource, type) ⇒ View
constructor
initializes a resource by json result.
- #inspect ⇒ Object
-
#method_missing(sym) ⇒ Object
delegate to attribute.
-
#properties ⇒ Object
returns properties which are member of the view’s type.
- #to_s ⇒ Object
-
#type ⇒ Object
return correspondent type.
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 |
#attributes ⇒ Object
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 |
#inspect ⇒ Object
27 28 29 |
# File 'lib/ken/view.rb', line 27 def inspect result = "#<View type=\"#{type.id || "nil"}\">" end |
#properties ⇒ Object
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_s ⇒ Object
16 17 18 |
# File 'lib/ken/view.rb', line 16 def to_s @type.to_s end |
#type ⇒ Object
return correspondent type
22 23 24 |
# File 'lib/ken/view.rb', line 22 def type @type end |