Class: Parser::ExtractPoints
- Inherits:
-
Object
- Object
- Parser::ExtractPoints
- Defined in:
- lib/simple_trail/parser/extract_points.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
-
#simplified_points ⇒ Object
readonly
Returns the value of attribute simplified_points.
Instance Method Summary collapse
-
#initialize(parsed_file) ⇒ ExtractPoints
constructor
A new instance of ExtractPoints.
- #read_points ⇒ Object
- #segment_points_selection(segment) ⇒ Object
- #simplified_points_selection(segment) ⇒ Object
Constructor Details
#initialize(parsed_file) ⇒ ExtractPoints
Returns a new instance of ExtractPoints.
7 8 9 |
# File 'lib/simple_trail/parser/extract_points.rb', line 7 def initialize(parsed_file) @parsed_file = parsed_file end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
5 6 7 |
# File 'lib/simple_trail/parser/extract_points.rb', line 5 def points @points end |
#simplified_points ⇒ Object (readonly)
Returns the value of attribute simplified_points.
5 6 7 |
# File 'lib/simple_trail/parser/extract_points.rb', line 5 def simplified_points @simplified_points end |
Instance Method Details
#read_points ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_trail/parser/extract_points.rb', line 11 def read_points main_node = @parsed_file.fetch(:trk) if main_node.is_a?(Array) @simplified_points = [] @points = [] main_node.each do |segment| @simplified_points << simplified_points_selection(segment) @points << segment_points_selection(segment) end @simplified_points.flatten! @points.flatten! else segments = main_node.fetch(:trkseg) @points = segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt] @simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } } end end |
#segment_points_selection(segment) ⇒ Object
33 34 35 36 |
# File 'lib/simple_trail/parser/extract_points.rb', line 33 def segment_points_selection(segment) segments = segment.fetch(:trkseg) segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt] end |
#simplified_points_selection(segment) ⇒ Object
38 39 40 |
# File 'lib/simple_trail/parser/extract_points.rb', line 38 def simplified_points_selection(segment) segment_points_selection(segment).map { |point| point.select { |key, _| [:lon, :lat].include? key } } end |