Class: NodeInfo
- Inherits:
-
Object
- Object
- NodeInfo
- Defined in:
- lib/puer/nodes.rb
Overview
NodeInfo contains the information from the xib, both hierarchy and properties
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node_class ⇒ Object
readonly
Returns the value of attribute node_class.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#subviews ⇒ Object
readonly
Returns the value of attribute subviews.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, node_id, node_class, subviews) ⇒ NodeInfo
constructor
A new instance of NodeInfo.
Constructor Details
#initialize(name, node_id, node_class, subviews) ⇒ NodeInfo
Returns a new instance of NodeInfo.
4 5 6 7 8 9 10 |
# File 'lib/puer/nodes.rb', line 4 def initialize(name, node_id, node_class, subviews) @name = name @node_id = node_id @node_class = node_class @subviews = subviews @properties = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/puer/nodes.rb', line 12 def name @name end |
#node_class ⇒ Object (readonly)
Returns the value of attribute node_class.
12 13 14 |
# File 'lib/puer/nodes.rb', line 12 def node_class @node_class end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
12 13 14 |
# File 'lib/puer/nodes.rb', line 12 def properties @properties end |
#subviews ⇒ Object (readonly)
Returns the value of attribute subviews.
12 13 14 |
# File 'lib/puer/nodes.rb', line 12 def subviews @subviews end |
Class Method Details
.enumerate(name) ⇒ Object
14 15 16 |
# File 'lib/puer/nodes.rb', line 14 def self.enumerate(name) "#{name}#{(@@name_counters ||= Hash.new {0})[name]+=1}" end |
.for(hierarchy, data, session) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puer/nodes.rb', line 18 def self.for(hierarchy, data, session) id = hierarchy['object-id'].to_s info = data[id] node_class = session.class_info_for info['class'] if node_class name = hierarchy['name'] || enumerate(node_class.name.downcase) subviews = (hierarchy['children'] || []).map {|child_hierarchy| NodeInfo.for(child_hierarchy, data, session)}.compact node = NodeInfo.new name, id, node_class, subviews info.each do |prop, value| if converter = session.converter_for(prop) props = converter.props_for(value) if props node.properties.merge! props else session.log(:error, "Could not convert #{prop}: #{value}") end else session.log(:warning, "Skipped property for #{info['class']}: #{prop}") unless session.ignore_property? prop end end node else session.log(:warning, "Skipped class #{info['class']}") unless session.ignore_class? info['class'] end node end |