Class: Floorplanner::DesignDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/floorplanner/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(fml_fn) ⇒ DesignDocument

Returns a new instance of DesignDocument.



35
36
37
# File 'lib/floorplanner/document.rb', line 35

def initialize(fml_fn)
  @xml = LibXML::XML::Document.file(fml_fn)
end

Instance Method Details

#save(fn) ⇒ Object



61
62
63
# File 'lib/floorplanner/document.rb', line 61

def save(fn)
  @xml.save fn
end

#update_heights(new_height) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/floorplanner/document.rb', line 39

def update_heights(new_height)
  lines = @xml.find("/design/lines/line[type='default_wall' or type='normal_wall' or contains(type,'hedge') or contains(type,'fence')]")
  lines.each do |line|
    begin
      points = line.find("points").first
      next unless points.content.include? ","

      coords = points.content.strip.split(",")
      top_coords = coords[1].strip.split(/\s/).map{|c| c.to_f}

      top_coords[2] = new_height
      top_coords[5] = new_height
      if top_coords.length > 6
        top_coords[8] = new_height
      end

      coords[1] = top_coords.join(" ")
      points.content = coords.join(",")
    rescue; end
  end
end