Class: Dxf::DesignToolPlanParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DesignToolPlanParser

Returns a new instance of DesignToolPlanParser.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/dxf/design_tool_plan_parser.rb', line 3

def options
  @options
end

#xml_dataObject (readonly)

Returns the value of attribute xml_data.



3
4
5
# File 'lib/dxf/design_tool_plan_parser.rb', line 3

def xml_data
  @xml_data
end

#xml_docObject (readonly)

Returns the value of attribute xml_doc.



3
4
5
# File 'lib/dxf/design_tool_plan_parser.rb', line 3

def xml_doc
  @xml_doc
end

Instance Method Details

#controlObject



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

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

#dxf_rawObject



22
23
24
25
26
# File 'lib/dxf/design_tool_plan_parser.rb', line 22

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

#flooring_typeObject



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

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

#initialize_xmlObject



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

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

#line_coordonatesObject



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

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



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

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

#room_typeObject



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

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

#save_to_file(file_handle) ⇒ Object



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

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



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

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