Class: GeoLabels::Importer::YamlData::ImportLabel

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_labels/importer/yaml_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ImportLabel

Returns a new instance of ImportLabel.



72
73
74
# File 'lib/geo_labels/importer/yaml_data.rb', line 72

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



70
71
72
# File 'lib/geo_labels/importer/yaml_data.rb', line 70

def name
  @name
end

#parentObject

Returns the value of attribute parent.



70
71
72
# File 'lib/geo_labels/importer/yaml_data.rb', line 70

def parent
  @parent
end

Instance Method Details

#add_child(label) ⇒ Object



90
91
92
93
94
# File 'lib/geo_labels/importer/yaml_data.rb', line 90

def add_child(label)
  children.push label
  label.parent = self
  label
end

#add_sibling(label) ⇒ Object



84
85
86
87
88
# File 'lib/geo_labels/importer/yaml_data.rb', line 84

def add_sibling(label)
  label.parent = parent
  parent.children.push label
  label
end

#childrenObject



80
81
82
# File 'lib/geo_labels/importer/yaml_data.rb', line 80

def children
  @children ||= LabelList.new
end

#inspectObject



96
97
98
99
100
101
102
# File 'lib/geo_labels/importer/yaml_data.rb', line 96

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

Returns:

  • (Boolean)


76
77
78
# File 'lib/geo_labels/importer/yaml_data.rb', line 76

def is_root?
  name == 'root'
end

#to_hObject



104
105
106
107
108
109
110
111
112
# File 'lib/geo_labels/importer/yaml_data.rb', line 104

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