Class: NJTransit::GTFS::Queries::RoutesBetween

Inherits:
Object
  • Object
show all
Defined in:
lib/njtransit/gtfs/queries/routes_between.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, from:, to:) ⇒ RoutesBetween

Returns a new instance of RoutesBetween.



9
10
11
12
13
# File 'lib/njtransit/gtfs/queries/routes_between.rb', line 9

def initialize(db, from:, to:)
  @db = db
  @from = from
  @to = to
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



7
8
9
# File 'lib/njtransit/gtfs/queries/routes_between.rb', line 7

def db
  @db
end

#fromObject (readonly)

Returns the value of attribute from.



7
8
9
# File 'lib/njtransit/gtfs/queries/routes_between.rb', line 7

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



7
8
9
# File 'lib/njtransit/gtfs/queries/routes_between.rb', line 7

def to
  @to
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/njtransit/gtfs/queries/routes_between.rb', line 15

def call
  from_stop_id = resolve_stop_id(from)
  to_stop_id = resolve_stop_id(to)

  return [] if from_stop_id.nil? || to_stop_id.nil?

  route_ids = find_common_route_ids(from_stop_id, to_stop_id)
  return [] if route_ids.empty?

  route_short_names(route_ids)
end