Class: NodeInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/puer/nodes.rb

Overview

NodeInfo contains the information from the xib, both hierarchy and properties

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/puer/nodes.rb', line 12

def name
  @name
end

#node_classObject (readonly)

Returns the value of attribute node_class.



12
13
14
# File 'lib/puer/nodes.rb', line 12

def node_class
  @node_class
end

#propertiesObject (readonly)

Returns the value of attribute properties.



12
13
14
# File 'lib/puer/nodes.rb', line 12

def properties
  @properties
end

#subviewsObject (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