Class: GeoLabels::Importer::ImportLabel
- Inherits:
-
Object
- Object
- GeoLabels::Importer::ImportLabel
- Defined in:
- lib/geo_labels/importer.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(label) ⇒ Object
- #add_sibling(label) ⇒ Object
- #children ⇒ Object
-
#initialize(name) ⇒ ImportLabel
constructor
A new instance of ImportLabel.
- #inspect ⇒ Object
- #is_root? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(name) ⇒ ImportLabel
Returns a new instance of ImportLabel.
85 86 87 |
# File 'lib/geo_labels/importer.rb', line 85 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
83 84 85 |
# File 'lib/geo_labels/importer.rb', line 83 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
83 84 85 |
# File 'lib/geo_labels/importer.rb', line 83 def parent @parent end |
Instance Method Details
#add_child(label) ⇒ Object
103 104 105 106 107 |
# File 'lib/geo_labels/importer.rb', line 103 def add_child(label) children.push label label.parent = self label end |
#add_sibling(label) ⇒ Object
97 98 99 100 101 |
# File 'lib/geo_labels/importer.rb', line 97 def add_sibling(label) label.parent = parent parent.children.push label label end |
#children ⇒ Object
93 94 95 |
# File 'lib/geo_labels/importer.rb', line 93 def children @children ||= LabelList.new end |
#inspect ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/geo_labels/importer.rb', line 109 def inspect # "#{name} => #{children.inspect}" # children.any? ? "<#{name}> => #{children.inpsect}" : "#{name}" base = name.to_s base = "#{base} => #{children.inspect}" if children.any? base end |
#is_root? ⇒ Boolean
89 90 91 |
# File 'lib/geo_labels/importer.rb', line 89 def is_root? name == 'root' end |
#to_h ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/geo_labels/importer.rb', line 117 def to_h if is_root? {labels: children.map(&:to_h)} else r = {name: name} r[:children] = children.map(&:to_h) if children.any? r end end |