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(subject, type) ⇒ View
constructor
initializes a subject (resource or topic) 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(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 |
#attributes ⇒ Object
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 |
#inspect ⇒ Object
26 27 28 |
# File 'lib/ken/view.rb', line 26 def inspect result = "#<View type=\"#{type.id || "nil"}\">" end |
#properties ⇒ Object
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_s ⇒ Object
15 16 17 |
# File 'lib/ken/view.rb', line 15 def to_s @type.to_s end |
#type ⇒ Object
return correspondent type
21 22 23 |
# File 'lib/ken/view.rb', line 21 def type @type end |