class TranslateYamlGenerator::Node
Attributes
children[R]
name[R]
parent[RW]
records[R]
Public Class Methods
new(name="")
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 39 def initialize(name="") @name = name @parent = nil @children = [] @records = [] end
Public Instance Methods
<<(item)
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 92 def <<(item) if item.is_a? TranslateYamlGenerator::Record add_record item elsif item.is_a? TranslateYamlGenerator::Node add_child item else raise ArgumentError, "not valid type" end end
add_child(child)
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 57 def add_child(child) @children << child child.parent = self end
add_record(record)
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 62 def add_record(record) @records << record end
find_child!(ns)
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 66 def find_child!(ns) return self if @name == ns find_child_r!(ns) end
find_child_r!(ns)
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 71 def find_child_r!(ns) return self if ns == "" token_list = ns.split(".") child_name = token_list[0] next_ns = token_list[1, token_list.length].join(".") @children.each do |child| return child.find_child_r! next_ns if child.name == child_name end if token_list.length == 1 node = TranslateYamlGenerator::Node.new child_name self << node return node else node = TranslateYamlGenerator::Node.new child_name self << node node.find_child! next_ns end end
fullname()
click to toggle source
# File lib/translate_yaml_generator/core.rb, line 46 def fullname token_list = [@name] parent = @parent while parent != nil token_list << parent.name parent = parent.parent end token_list.reject! { |c| c.empty? } token_list.reverse.join(".") end