atco 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -3,7 +3,10 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'open3'
5
5
  require 'tempfile'
6
- require 'location'
6
+ require 'atco/location'
7
+ require 'atco/journey'
8
+ require 'atco/stop'
9
+
7
10
 
8
11
  module Atco
9
12
  VERSION = '0.0.1'
@@ -52,9 +55,9 @@ module Atco
52
55
 
53
56
  if current_journey
54
57
  if journeys[current_journey[:unique_journey_identifier]]
55
- journeys[current_journey[:unique_journey_identifier]] << object
58
+ journeys[current_journey[:unique_journey_identifier]].stops << Stop.new(object)
56
59
  else
57
- journeys[current_journey[:unique_journey_identifier]] = [object]
60
+ journeys[current_journey[:unique_journey_identifier]] = Journey.new(object)
58
61
  end
59
62
  end
60
63
  objects << object
@@ -0,0 +1,66 @@
1
+ module Atco
2
+
3
+ class Journey
4
+
5
+ attr_accessor :vehicle_type, :registration_number, :identifier, :operator, :route_number,
6
+ :first_date_of_operation, :running_board, :last_date_of_operation, :school_term_time, :route_direction, :bank_holidays
7
+
8
+ attr_accessor :stops
9
+
10
+ def initialize(data)
11
+ @mondays = parse_boolean_int data[:operates_on_mondays]
12
+ @tuesdays = parse_boolean_int data[:operates_on_tuesdays]
13
+ @wednesdays = parse_boolean_int data[:operates_on_wednesdays]
14
+ @thursdays = parse_boolean_int data[:operates_on_thursdays]
15
+ @fridays = parse_boolean_int data[:operates_on_fridays]
16
+ @saturdays = parse_boolean_int data[:operates_on_saturdays]
17
+ @sundays = parse_boolean_int data[:operates_on_sundays]
18
+
19
+ @vehicle_type = data[:vehicle_type]
20
+ @registration_number = data[:registration_number]
21
+ @identifier = data[:unique_journey_identifier]
22
+ @operator = data[:operator]
23
+ @route_number = data[:route_number]
24
+ @route_direction = data[:route_direction]
25
+ @first_date_of_operation = data[:first_date_of_operation]
26
+ @last_date_of_operation = data[:last_date_of_operation]
27
+ @running_board = data[:running_board]
28
+ @school_term_time = data[:school_term_time]
29
+ @bank_holidays = data[:bank_holidays]
30
+
31
+ @stops = []
32
+ #stops.each do |s|
33
+ # @stops << Stop.new(s)
34
+ #end
35
+ end
36
+
37
+ def mondays?; @mondays; end
38
+ def tuesdays?; @tuesdays; end
39
+ def wednesdays?; @wednesdays; end
40
+ def thursdays?; @thursdays; end
41
+ def fridays?; @fridays; end
42
+ def saturdays?; @saturdays; end
43
+ def sundays?; @sundays; end
44
+
45
+ def parse_boolean_int(string)
46
+ (string && string == "1") ? true : false
47
+ end
48
+
49
+ def to_json(*args)
50
+ {
51
+ :vehicle_type => @vehicle_type,
52
+ :registration_number => @registration_number,
53
+ :identifier => @identifier,
54
+ :operator => @operator,
55
+ :route_number => @route_number,
56
+ :first_date_of_operation => @first_date_of_operation,
57
+ :running_board => @running_board,
58
+ :last_date_of_operation => @last_date_of_operation,
59
+ :school_term_time => @school_term_time,
60
+ :route_direction => @route_direction,
61
+ :bank_holidays => @bank_holidays,
62
+ :stops => @stops
63
+ }.to_json(*args)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,27 @@
1
+ module Atco
2
+
3
+ class Location
4
+
5
+ attr_accessor :name, :identifier, :easting, :northing, :gazeteer_code
6
+
7
+ def initialize(location_header, additional_location_information)
8
+ @name = location_header[:full_location]
9
+ @identifier = location_header[:record_identity]
10
+ @easting = additional_location_information[:grid_reference_easting]
11
+ @northing = additional_location_information[:grid_reference_northing]
12
+ @gazeteer_code = location_header[:gazetteer_code]
13
+ end
14
+
15
+ def to_json(*a)
16
+ {
17
+ :name => @name,
18
+ :identifier => @identifier,
19
+ :easting => @easting,
20
+ :northing => @northing,
21
+ :gazeteer_code => @gazeteer_code
22
+ }.to_json(*a)
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,31 @@
1
+ module Atco
2
+
3
+ class Stop
4
+
5
+ attr_accessor :bay_number, :location, :timing_point_indicator, :fare_stage_indicator, :published_departure_time, :record_identity
6
+
7
+ def origin?; @record_identity == "QO"; end
8
+ def intermediate?; @record_identity == "QI"; end
9
+ def destination?; @record_identity == "QT"; end
10
+
11
+ def initialize(data)
12
+ @bay_number = data[:bay_number]
13
+ @location = data[:location]
14
+ @timing_point_indicator = data[:timing_point_indicator]
15
+ @fare_stage_indicator = data[:fare_stage_indicator]
16
+ @published_departure_time = data[:published_departure_time]
17
+ @record_identity = data[:record_identity]
18
+ end
19
+
20
+ def to_json(*args)
21
+ {
22
+ :record_identity => @record_identity,
23
+ :location => @location,
24
+ :published_departure_time => @published_departure_time,
25
+ :timing_point_indicator => @timing_point_indicator,
26
+ :fare_stage_indicator => @fare_stage_indicator,
27
+ :bay_number => @bay_number
28
+ }.to_json(*args)
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Rice
@@ -31,7 +31,9 @@ files:
31
31
  - Rakefile
32
32
  - VERSION
33
33
  - lib/atco.rb
34
- - lib/location.rb
34
+ - lib/atco/journey.rb
35
+ - lib/atco/location.rb
36
+ - lib/atco/stop.rb
35
37
  has_rdoc: true
36
38
  homepage: http://github.com/davidjrice/atco
37
39
  licenses: []
@@ -1,23 +0,0 @@
1
- class Location
2
-
3
- attr_accessor :name, :identifier, :easting, :northing, :gazeteer_code
4
-
5
- def initialize(location_header, additional_location_information)
6
- @name = location_header[:full_location]
7
- @identifier = location_header[:record_identity]
8
- @easting = additional_location_information[:grid_reference_easting]
9
- @northing = additional_location_information[:grid_reference_northing]
10
- @gazeteer_code = location_header[:gazetteer_code]
11
- end
12
-
13
- def to_json(*a)
14
- {
15
- :name => @name,
16
- :identifier => @identifier,
17
- :easting => @easting,
18
- :northing => @northing,
19
- :gazeteer_code => @gazeteer_code
20
- }.to_json(*a)
21
- end
22
-
23
- end