Class: GTFS::Realtime::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/gtfs/realtime/database.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.database_path=(value) ⇒ Object (writeonly)

Sets the attribute database_path

Parameters:

  • value

    the value to set the attribute database_path to.



5
6
7
# File 'lib/gtfs/realtime/database.rb', line 5

def database_path=(value)
  @database_path = value
end

Class Method Details

.model_classesObject



113
114
115
# File 'lib/gtfs/realtime/database.rb', line 113

def model_classes
  ObjectSpace.each_object(::Class).select{|klass| klass <= GTFS::Realtime::Model}
end

.path=(new_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gtfs/realtime/database.rb', line 7

def path=(new_path)
  @path = new_path

  # This script sets up an in-memory DB so that it can be used by this gem.
  # It also extends Sequel::Model so that Sequel may be used independently by
  # the parent project if desired.
  db = Sequel.connect(new_path || "sqlite://")

  # Set up all database tables
  db.create_table? :gtfs_realtime_routes do
    String :id, primary_key: true
    String :short_name
    String :long_name
    String :url

    index :id
  end

  db.create_table? :gtfs_realtime_shapes do
    String :id
    Integer :sequence
    Double :latitude
    Double :longitude

    index :id
  end

  db.create_table? :gtfs_realtime_stops do
    String :id, primary_key: true
    String :name
    Double :latitude
    Double :longitude

    index :id
  end

  db.create_table? :gtfs_realtime_stop_times do
    String :trip_id
    String :stop_id
    String :arrival_time
    String :departure_time
    Integer :stop_sequence

    index :trip_id
    index :stop_id
  end

  db.create_table? :gtfs_realtime_trips do
    String :id, primary_key: true
    String :headsign
    String :route_id
    String :service_id
    String :shape_id

    index :id
    index :route_id
  end

  db.create_table? :gtfs_realtime_trip_updates do
    String :id, primary_key: true
    String :trip_id
    String :route_id

    index :id
  end

  db.create_table? :gtfs_realtime_stop_time_updates do
    String :trip_update_id
    String :stop_id
    Integer :arrival_delay
    Time :arrival_time
    Integer :departure_delay
    Time :departure_time

    index :trip_update_id
    index :stop_id
  end

  db.create_table? :gtfs_realtime_vehicle_positions do
    String :trip_id
    String :stop_id
    Double :latitude
    Double :longitude
    Double :bearing
    Time :timestamp

    index :trip_id
    index :stop_id
  end

  db.create_table? :gtfs_realtime_service_alerts do
    String :stop_id
    String :header_text
    Text :description_text
    Time :start_time
    Time :end_time

    index :stop_id
  end

  # Set up all gtfs-realtime models to use this database
  model_classes.each do |model_class|
    model_class.db = db
  end
end