Class: GpxDoctor::Builder
- Inherits:
-
Object
- Object
- GpxDoctor::Builder
- Defined in:
- lib/gpx_doctor/builder.rb
Constant Summary collapse
- GPX_NS =
'http://www.topografix.com/GPX/1/1'- XSI_NS =
'http://www.w3.org/2001/XMLSchema-instance'- SCHEMA_LOCATION =
"#{GPX_NS} http://www.topografix.com/GPX/1/1/gpx.xsd"
Class Method Summary collapse
- .build(result, creator: 'GPX Doctor') ⇒ Object
- .build_file(result, file_path, creator: 'GPX Doctor') ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(result, creator: 'GPX Doctor') ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(result, creator: 'GPX Doctor') ⇒ Builder
Returns a new instance of Builder.
23 24 25 26 |
# File 'lib/gpx_doctor/builder.rb', line 23 def initialize(result, creator: 'GPX Doctor') @result = result @creator = creator end |
Class Method Details
.build(result, creator: 'GPX Doctor') ⇒ Object
12 13 14 |
# File 'lib/gpx_doctor/builder.rb', line 12 def build(result, creator: 'GPX Doctor') new(result, creator: creator).build end |
.build_file(result, file_path, creator: 'GPX Doctor') ⇒ Object
16 17 18 19 20 |
# File 'lib/gpx_doctor/builder.rb', line 16 def build_file(result, file_path, creator: 'GPX Doctor') xml = build(result, creator: creator) File.write(file_path, xml) xml end |
Instance Method Details
#build ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gpx_doctor/builder.rb', line 28 def build builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.gpx( 'version' => '1.1', 'creator' => @creator, 'xmlns' => GPX_NS, 'xmlns:xsi' => XSI_NS, 'xsi:schemaLocation' => SCHEMA_LOCATION ) do (xml, @result.) if @result. @result.waypoints.each { |wpt| build_waypoint(xml, wpt, tag: 'wpt') } @result.routes.each { |rte| build_route(xml, rte) } @result.tracks.each { |trk| build_track(xml, trk) } end end builder.to_xml end |