ttc-gps 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ begin
12
12
  gem.authors = ["Scott Hyndman"]
13
13
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
14
  gem.add_development_dependency "geokit", ">= 0"
15
+ gem.add_development_dependency "json", ">= 0"
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
17
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.4.0
@@ -1,6 +1,3 @@
1
- require 'rubygems'
2
- require 'geokit'
3
-
4
1
  # Extensions to Geokit.
5
2
  module Geokit
6
3
  class Bounds
@@ -16,6 +13,22 @@ module Geokit
16
13
  ne.lon = ne.lon + units
17
14
  ne.lng = ne.lng + units
18
15
  end
16
+
17
+ def to_json *args
18
+ {
19
+ 'sw' => @sw,
20
+ 'ne' => @ne
21
+ }.to_json(*args)
22
+ end
23
+ end
24
+
25
+ class LatLng
26
+ def to_json *args
27
+ {
28
+ 'lat' => @lat,
29
+ 'lng' => @lng
30
+ }.to_json(*args)
31
+ end
19
32
  end
20
33
  end
21
34
 
@@ -23,9 +36,17 @@ module TTC
23
36
  # <vehicle lon='-79.3582' secsSinceReport='7' predictable='true' speedKmHr='0.0' dirTag='504_westbound' id='4142' heading='54' lat='43.677082' routeTag='504'/>
24
37
  class Vehicle
25
38
  attr_accessor :id, :route, :position, :heading, :dir, :secs_since_report, :predictable
26
-
27
- def to_s
28
- inspect
39
+
40
+ def to_json *args
41
+ {
42
+ 'id' => @id,
43
+ 'route' => @route,
44
+ 'position' => @position,
45
+ 'heading' => @heading,
46
+ 'dir' => @dir,
47
+ 'secs_since_report' => @secs_since_report,
48
+ 'predictable' => @predictable
49
+ }.to_json(*args)
29
50
  end
30
51
 
31
52
  # Parses an XML element into a Vehicle instance
@@ -35,11 +56,7 @@ module TTC
35
56
  v = Vehicle.new
36
57
  v.id = attrs["id"]
37
58
  v.route = attrs["routeTag"]
38
-
39
- lon = Float(attrs["lon"])
40
- lat = Float(attrs["lat"])
41
- v.position = Geokit::LatLng.new(lat, lon)
42
-
59
+ v.position = Geokit::LatLng.new(Float(attrs["lat"]), Float(attrs["lon"]))
43
60
  v.heading = Float(attrs["heading"])
44
61
  v.dir = attrs["dirTag"]
45
62
  v.secs_since_report = Integer(attrs["secsSinceReport"])
@@ -86,8 +103,15 @@ module TTC
86
103
  get_closest_stops[0]
87
104
  end
88
105
 
89
- def to_s
90
- inspect
106
+ #:tag, :title, :bounds, :stop_map, :directions
107
+
108
+ def to_json *args
109
+ {
110
+ 'tag' => @tag,
111
+ 'title' => @title,
112
+ 'bounds' => @bounds,
113
+ 'directions' => @directions
114
+ }.to_json(*args)
91
115
  end
92
116
 
93
117
  def Route.parse_element element
@@ -96,16 +120,9 @@ module TTC
96
120
  r = Route.new
97
121
  r.tag = attrs["tag"]
98
122
  r.title = attrs["title"]
99
-
100
- lat_min = Float(attrs["latMin"])
101
- lat_max = Float(attrs["latMax"])
102
- lon_min = Float(attrs["lonMin"])
103
- lon_max = Float(attrs["lonMax"])
104
-
105
123
  r.bounds = Geokit::Bounds.new(
106
- Geokit::LatLng.new(lat_min, lon_min),
107
- Geokit::LatLng.new(lat_max, lon_max))
108
-
124
+ Geokit::LatLng.new(Float(attrs["latMin"]), Float(attrs["lonMin"])),
125
+ Geokit::LatLng.new(Float(attrs["latMax"]), Float(attrs["lonMax"])))
109
126
  r
110
127
  end
111
128
  end
@@ -114,8 +131,14 @@ module TTC
114
131
  class Stop
115
132
  attr_accessor :id, :title, :position, :dir, :tag
116
133
 
117
- def to_s
118
- inspect
134
+ def to_json *args
135
+ {
136
+ 'id' => @id,
137
+ 'title' => @title,
138
+ 'position' => @position,
139
+ 'dir' => @dir,
140
+ 'tag' => @tag
141
+ }.to_json(*args)
119
142
  end
120
143
 
121
144
  # Parses an XML element into a Stop instance
@@ -125,9 +148,7 @@ module TTC
125
148
  s = Stop.new
126
149
  s.id = attrs["stopId"]
127
150
  s.title = attrs["title"]
128
- lat = Float(attrs["lat"])
129
- lon = Float(attrs["lon"])
130
- s.position = Geokit::LatLng.new(lat, lon)
151
+ s.position = Geokit::LatLng.new(Float(attrs["lat"]), Float(attrs["lon"]))
131
152
  s.dir = attrs["dirTag"]
132
153
  s.tag = attrs["tag"]
133
154
  s
data/lib/ttc-gps.rb CHANGED
@@ -2,5 +2,5 @@ require 'ttc-gps/extensions'
2
2
  require 'ttc-gps/constants'
3
3
  require 'ttc-gps/models'
4
4
  require 'ttc-gps/service'
5
- require 'rubygems'
6
- require 'geokit'
5
+ require 'geokit'
6
+ require 'json'
data/ttc-gps.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ttc-gps}
8
- s.version = "0.2.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Scott Hyndman"]
@@ -49,13 +49,16 @@ Gem::Specification.new do |s|
49
49
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
50
  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
51
  s.add_development_dependency(%q<geokit>, [">= 0"])
52
+ s.add_development_dependency(%q<json>, [">= 0"])
52
53
  else
53
54
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
55
  s.add_dependency(%q<geokit>, [">= 0"])
56
+ s.add_dependency(%q<json>, [">= 0"])
55
57
  end
56
58
  else
57
59
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
60
  s.add_dependency(%q<geokit>, [">= 0"])
61
+ s.add_dependency(%q<json>, [">= 0"])
59
62
  end
60
63
  end
61
64
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttc-gps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 4
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Hyndman
@@ -46,6 +46,20 @@ dependencies:
46
46
  version: "0"
47
47
  type: :development
48
48
  version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
49
63
  description: Uses NextBus data.
50
64
  email: scotty.hyndman@gmail.com
51
65
  executables: []