Class: ActiveRoad::OsmPbfImporter::EndpointToWayMap

Inherits:
Object
  • Object
show all
Defined in:
app/models/active_road/osm_pbf_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEndpointToWayMap

Returns a new instance of EndpointToWayMap.



200
201
202
# File 'app/models/active_road/osm_pbf_importer.rb', line 200

def initialize
  @endpoints = {}
end

Instance Attribute Details

#endpointsObject

Returns the value of attribute endpoints.



198
199
200
# File 'app/models/active_road/osm_pbf_importer.rb', line 198

def endpoints
  @endpoints
end

Instance Method Details

#add_way(way) ⇒ Object



204
205
206
207
208
209
210
# File 'app/models/active_road/osm_pbf_importer.rb', line 204

def add_way(way)
  if get_from_either_end(way).present?
    raise StandardError, "Call to add_way would overwrite existing way(s)"
  end
  self.endpoints[way.points.first] = way
  self.endpoints[way.points.last] = way
end

#get_from_either_end(way) ⇒ Object



217
218
219
220
221
222
# File 'app/models/active_road/osm_pbf_importer.rb', line 217

def get_from_either_end(way)
  [].tap do |selected_end_points|
    selected_end_points << endpoints[way.points.first] if endpoints.include?(way.points.first)
    selected_end_points << endpoints[way.points.last] if endpoints.include?(way.points.last)
  end
end

#number_of_endpointsObject



224
225
226
# File 'app/models/active_road/osm_pbf_importer.rb', line 224

def number_of_endpoints
  return endpoints.size
end

#remove_way(way) ⇒ Object



212
213
214
215
# File 'app/models/active_road/osm_pbf_importer.rb', line 212

def remove_way(way)
  endpoints.delete(way.points.first)
  endpoints.delete(way.points.last)
end