Class: Dxf::DesignToolPlanParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dxf/design_tool_plan_parser.rb

Overview

Parses an XML floor-plan blob produced by the in-browser Floor-Heating
Design Tool into a Ruby object tree (rooms, fixtures, blocks) that the
server can convert into a RoomConfiguration and matching DXF/SVG
exports. Accepts either a :file_path or a raw :xml_data string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DesignToolPlanParser

Returns a new instance of DesignToolPlanParser.



9
10
11
12
13
# File 'lib/dxf/design_tool_plan_parser.rb', line 9

def initialize(options = {})
  @options = options
  raise "Need a :file_path or a :xml_data argument" if @options[:file_path].nil? && @options[:xml_data].nil?
  raise "File #{@options[:file_path]} does not exist" if @options[:file_path].present? && !File.exist?(@options[:file_path])
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/dxf/design_tool_plan_parser.rb', line 7

def options
  @options
end

#xml_dataObject (readonly)

Returns the value of attribute xml_data.



7
8
9
# File 'lib/dxf/design_tool_plan_parser.rb', line 7

def xml_data
  @xml_data
end

#xml_docObject (readonly)

Returns the value of attribute xml_doc.



7
8
9
# File 'lib/dxf/design_tool_plan_parser.rb', line 7

def xml_doc
  @xml_doc
end

Instance Method Details

#controlObject



51
52
53
# File 'lib/dxf/design_tool_plan_parser.rb', line 51

def control
  xml_doc.at_xpath("//ControlPlacement").content
end

#dxf_rawObject



26
27
28
29
30
# File 'lib/dxf/design_tool_plan_parser.rb', line 26

def dxf_raw
  initialize_xml
  fp = Dxf::FloorPlan.new(to_hash, room_type, flooring_type)
  fp.dxf
end

#flooring_typeObject



41
42
43
# File 'lib/dxf/design_tool_plan_parser.rb', line 41

def flooring_type
  xml_doc.at_xpath("//FlooringType").content
end

#initialize_xmlObject



15
16
17
18
# File 'lib/dxf/design_tool_plan_parser.rb', line 15

def initialize_xml
  @xml_data = options[:xml_data] || File.read(options[:file_path])
  @xml_doc = Nokogiri::XML(@xml_data)
end

#line_coordonatesObject



45
46
47
48
49
# File 'lib/dxf/design_tool_plan_parser.rb', line 45

def line_coordonates
  # xml_doc.at_xpath("//Project//Room//DrawingInfo//UserFloorPlan//RoomShape").content
  xml_doc.xpath("//Project//Room//DrawingInfo//UserFloorPlan//RoomShape")
  #  lines = @xml_doc.xpath("//Project//Room//DrawingInfo//UserFloorPlan//RoomShape//Line")
end

#project_infoObject



55
56
57
# File 'lib/dxf/design_tool_plan_parser.rb', line 55

def project_info
  xml_doc.xpath("//Project", 'projectid' => 'projectid')
end

#room_typeObject



37
38
39
# File 'lib/dxf/design_tool_plan_parser.rb', line 37

def room_type
  xml_doc.at_xpath("//RoomType").content
end

#save_to_file(file_handle) ⇒ Object



20
21
22
23
24
# File 'lib/dxf/design_tool_plan_parser.rb', line 20

def save_to_file(file_handle)
  initialize_xml
  fp = Dxf::FloorPlan.new(to_hash, room_type, flooring_type)
  file_handle.write(fp.dxf)
end

#to_hashObject



32
33
34
35
# File 'lib/dxf/design_tool_plan_parser.rb', line 32

def to_hash
  parser = Nori.new(parser: :nokogiri)
  parser.parse @xml_data
end