Class: GpxDoctor::Parser
- Inherits:
-
Object
- Object
- GpxDoctor::Parser
- Defined in:
- lib/gpx_doctor/parser.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- GPX_NS =
'http://www.topografix.com/GPX/1/1'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(doc, ns, params: {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(doc, ns, params: {}) ⇒ Parser
Returns a new instance of Parser.
37 38 39 40 41 |
# File 'lib/gpx_doctor/parser.rb', line 37 def initialize(doc, ns, params: {}) @doc = doc @ns = ns @params = params end |
Class Method Details
.parse(file_path, params: {}) ⇒ Object
17 18 19 20 |
# File 'lib/gpx_doctor/parser.rb', line 17 def parse(file_path, params: {}) xml = File.read(file_path) parse_string(xml, params: params) end |
.parse_string(xml_string, params: {}) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/gpx_doctor/parser.rb', line 22 def parse_string(xml_string, params: {}) doc = Nokogiri::XML(xml_string) ns = detect_namespace(doc) new(doc, ns, params: params).parse end |
Instance Method Details
#parse ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gpx_doctor/parser.rb', line 43 def parse result = Result.new( waypoints: parse_waypoints, routes: parse_routes, tracks: parse_tracks, metadata: ) eff_max_dist = @params[:max_distance] || effective_max_distance(result) split_segments(result, eff_max_dist) if eff_max_dist select_max_points(result) if @params[:max_points] enhance_statistics(result) if @params[:segment_statistics] enhance_elevations(result) if @params[:enhance_elevation] result end |