Class: ActiveRecordPolyline::Polyline
- Inherits:
-
Object
- Object
- ActiveRecordPolyline::Polyline
- Defined in:
- lib/active_record_polyline/polyline.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
-
#initialize(points = [], **options) ⇒ Polyline
constructor
A new instance of Polyline.
- #push(longitude:, latitude:, skip_compaction: false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(points = [], **options) ⇒ Polyline
Returns a new instance of Polyline.
9 10 11 12 13 14 15 16 17 |
# File 'lib/active_record_polyline/polyline.rb', line 9 def initialize(points = [], **) points = FastPolylines.decode(points, 5) if points.is_a?(String) points = points.map(&method(:cast_array_to_hash)) if points.first.is_a?(Array) @points = points compressor_name = .delete(:name) @compressor = Compaction.lookup(compressor_name).new(**) @compressor.apply self end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
7 8 9 |
# File 'lib/active_record_polyline/polyline.rb', line 7 def points @points end |
Instance Method Details
#push(longitude:, latitude:, skip_compaction: false) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record_polyline/polyline.rb', line 23 def push(longitude:, latitude:, skip_compaction: false) @compressor.push( location: { longitude: longitude, latitude: latitude, }, skip_compaction: skip_compaction ) end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/active_record_polyline/polyline.rb', line 19 def to_s FastPolylines.encode(@points.map { |point| [point[:latitude], point[:longitude]] }, 5) end |