Class: StructureButcher
- Inherits:
-
Object
- Object
- StructureButcher
- Defined in:
- lib/structurebutcher.rb
Overview
vyndavator, zastamdator amputovat, implantovat amputate, implantate
Defined Under Namespace
Instance Method Summary collapse
- #amputate(body, slot) ⇒ Object
- #amputate_file(body_file, slot, part_file, format) ⇒ Object
- #implantate(body, slot, part) ⇒ Object
- #implantate_file(body_file, slot, part_file, format) ⇒ Object
Instance Method Details
#amputate(body, slot) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/structurebutcher.rb', line 14 def amputate(body, slot) keys = slot.split('.') result = body while (key = keys.shift) result = result[key] end return result end |
#amputate_file(body_file, slot, part_file, format) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/structurebutcher.rb', line 33 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) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/structurebutcher.rb', line 23 def implantate(body, slot, part) keys = slot.split('.') last_key = keys.pop area = body while (key = keys.shift) area = area[key] #TODO: create hash if not exists end area[last_key] = part end |
#implantate_file(body_file, slot, part_file, format) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/structurebutcher.rb', line 44 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) butcher = StructureButcher.new part = butcher.implantate(body, slot, part) storer = StructureButcher::Storer.new storer.save_structure(body, body_file, "yaml") end |