Class: Dxf::DesignToolPlanParser
- Inherits:
-
Object
- Object
- Dxf::DesignToolPlanParser
- 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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#xml_data ⇒ Object
readonly
Returns the value of attribute xml_data.
-
#xml_doc ⇒ Object
readonly
Returns the value of attribute xml_doc.
Instance Method Summary collapse
-
#control ⇒ String
The control placement.
-
#dxf_raw ⇒ String
The generated DXF content.
-
#flooring_type ⇒ String
The flooring type.
-
#initialize(options = {}) ⇒ DesignToolPlanParser
constructor
A new instance of DesignToolPlanParser.
-
#initialize_xml ⇒ Nokogiri::XML::Document
The parsed XML document.
-
#line_coordonates ⇒ Nokogiri::XML::NodeSet
The RoomShape nodes.
-
#project_info ⇒ Nokogiri::XML::NodeSet
The Project nodes.
-
#room_type ⇒ String
The room type.
-
#save_to_file(file_handle) ⇒ Integer
Number of bytes written to the file handle.
-
#to_hash ⇒ Hash
The parsed XML as a hash.
Constructor Details
#initialize(options = {}) ⇒ DesignToolPlanParser
Returns a new instance of DesignToolPlanParser.
13 14 15 16 17 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 13 def initialize( = {}) @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
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 7 def @options end |
#xml_data ⇒ Object (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_doc ⇒ Object (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
#control ⇒ String
Returns the control placement.
63 64 65 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 63 def control xml_doc.at_xpath("//ControlPlacement").content end |
#dxf_raw ⇒ String
Returns the generated DXF content.
33 34 35 36 37 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 33 def dxf_raw initialize_xml fp = Dxf::FloorPlan.new(to_hash, room_type, flooring_type) fp.dxf end |
#flooring_type ⇒ String
Returns the flooring type.
51 52 53 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 51 def flooring_type xml_doc.at_xpath("//FlooringType").content end |
#initialize_xml ⇒ Nokogiri::XML::Document
Returns the parsed XML document.
20 21 22 23 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 20 def initialize_xml @xml_data = [:xml_data] || File.read([:file_path]) @xml_doc = Nokogiri::XML(@xml_data) end |
#line_coordonates ⇒ Nokogiri::XML::NodeSet
Returns the RoomShape nodes.
56 57 58 59 60 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 56 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_info ⇒ Nokogiri::XML::NodeSet
Returns the Project nodes.
68 69 70 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 68 def project_info xml_doc.xpath("//Project", 'projectid' => 'projectid') end |
#room_type ⇒ String
Returns the room type.
46 47 48 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 46 def room_type xml_doc.at_xpath("//RoomType").content end |
#save_to_file(file_handle) ⇒ Integer
Returns number of bytes written to the file handle.
26 27 28 29 30 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 26 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_hash ⇒ Hash
Returns the parsed XML as a hash.
40 41 42 43 |
# File 'lib/dxf/design_tool_plan_parser.rb', line 40 def to_hash parser = Nori.new(parser: :nokogiri) parser.parse @xml_data end |