class StructureButcher
vyndavator, zastamdator amputovat, implantovat amputate, implantate
Public Instance Methods
amputate(body, slot)
click to toggle source
# File lib/structurebutcher.rb, line 22 def amputate(body, slot) keys = split_escape(slot) result = body while (key = keys.shift) result = result[key] end return result end
amputate_file(body_file, slot, part_file, format)
click to toggle source
# File lib/structurebutcher.rb, line 49 def amputate_file(body_file, slot, part_file, format) parser = StructureButcher::Parser.new body = parser.load_structure(body_file, "yaml") butcher = StructureButcher.new part = butcher.amputate(body, slot) storer = StructureButcher::Storer.new storer.save_structure(part, part_file, format) end
implantate(body, slot, part)
click to toggle source
# File lib/structurebutcher.rb, line 31 def implantate(body, slot, part) keys = split_escape(slot) last_key = keys.pop area = body if not area area = Hash.new end while (key = keys.shift) if not area.has_key?(key) then area[key] = {} end area = area[key] end area[last_key] = part end
implantate_file(body_file, slot, part_file, format)
click to toggle source
# File lib/structurebutcher.rb, line 60 def implantate_file(body_file, slot, part_file, format) parser = StructureButcher::Parser.new body = parser.load_structure(body_file, "yaml") part = parser.load_structure(part_file, format) # make sure we work with hash # it does not make sense to work with anything else if not body.is_a?(Hash) body = Hash.new end butcher = StructureButcher.new part = butcher.implantate(body, slot, part) storer = StructureButcher::Storer.new storer.save_structure(body, body_file, "yaml") end
implantate_struct_into_file(body_file, slot, part_struct)
click to toggle source
# File lib/structurebutcher.rb, line 79 def implantate_struct_into_file(body_file, slot, part_struct) parser = StructureButcher::Parser.new body = parser.load_structure(body_file, "yaml") # make sure we work with hash # it does not make sense to work with anything else if not body.is_a?(Hash) body = Hash.new end butcher = StructureButcher.new butcher.implantate(body, slot, part_struct) storer = StructureButcher::Storer.new storer.save_structure(body, body_file, "yaml") end
split_escape(str)
click to toggle source
# File lib/structurebutcher.rb, line 14 def split_escape(str) output = [] str.scan(/(?>\\.|[^\\.])+/) do |chunk| output.push( chunk.gsub(/\\(.)/, '\1') ) end return output end