london_transport 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e1a8ed1303ee5dced5f837dd15335d3c31694b0
4
- data.tar.gz: ac9eeaef1f095a20e28db9ff12424b8cec66f9fa
3
+ metadata.gz: cd9f6b195b362db7349a64f7487a98b6959555a0
4
+ data.tar.gz: df7ab97282e4c0902ac8044e3e162319aa8ed77a
5
5
  SHA512:
6
- metadata.gz: 7eb7a6e0526c26c9e1f73013b57add5f1248aad877256347823283280ad5fd904ba5e6254fde91a4fc70dc074855391a6b5486bae00580db133552e1809a260b
7
- data.tar.gz: f00f9c4da208205e9e3cb13e6bb8290de7870c085192966320a7b02b58c7ec9abeb992994821ad9f846134e2c1d4cd9db2d924f6b8d8612a9ff4067b27a48b64
6
+ metadata.gz: c9caaa0f0d91720f69091f2dc027f47ef379b76255e02a6297320856c9406e499c7d0db730682e8949aa8c0d08bee466ffc8596aac005b724359220aa6dbf626
7
+ data.tar.gz: 6ee9469264cce7869e591d7cb88465aea23b16bbae83d79090163540057bce75db907a71c115505e73b776d244ebc5169a82ac15a323f90ff1f41fd3990c57f7
@@ -4,9 +4,12 @@ module LondonTransport
4
4
  end
5
5
  end
6
6
 
7
+ require 'net/http'
7
8
  require 'oj'
8
9
  require 'london_transport/version'
9
10
  require 'london_transport/base'
11
+ require 'london_transport/line'
12
+ require 'london_transport/combined'
10
13
  require 'london_transport/train'
11
14
  require 'london_transport/tube'
12
15
  require 'london_transport/bus'
@@ -3,6 +3,7 @@ class LondonTransport::Base
3
3
  API_ENDPOINT = "https://api.tfl.gov.uk/StopPoint"
4
4
  STOP_TYPES = []
5
5
  MODES = []
6
+ AVAILABLE_MODES_OF_TRANSPORT = ['bus', 'train', 'tube']
6
7
 
7
8
  def initialize(longitude:, latitude:, radius: 500)
8
9
  @longitude = longitude
@@ -15,7 +16,15 @@ class LondonTransport::Base
15
16
  return distances unless nearest
16
17
 
17
18
  nearest['stopPoints'][0..limit - 1].each do |station|
18
- distances << { station['commonName'] => station['distance'] }
19
+ line = LondonTransport::Line.new(station['lineModeGroups'])
20
+
21
+ distances << {
22
+ station['commonName'] => {
23
+ distance: station['distance'],
24
+ modes: self.class::MODES || station['modes'],
25
+ lines: line.names
26
+ }
27
+ }
19
28
  end
20
29
 
21
30
  distances
@@ -35,7 +44,6 @@ class LondonTransport::Base
35
44
  end
36
45
 
37
46
  def nearest
38
- Oj.load(Net::HTTP.get(api_endpoint))
47
+ Oj.load(::Net::HTTP.get(api_endpoint))
39
48
  end
40
-
41
49
  end
@@ -0,0 +1,16 @@
1
+ class LondonTransport::Combined < LondonTransport::Base
2
+ private
3
+ def stop_types
4
+ @stop_types ||= combined_data(constant_name: 'STOP_TYPES').flatten.uniq.join(',')
5
+ end
6
+
7
+ def modes
8
+ @modes ||= combined_data(constant_name: 'MODES').flatten.uniq.join(',')
9
+ end
10
+
11
+ def combined_data(constant_name:)
12
+ LondonTransport::Base::AVAILABLE_MODES_OF_TRANSPORT.map do |transport|
13
+ Module.const_get("LondonTransport::#{transport.capitalize}::#{constant_name}")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class LondonTransport::Line
2
+ def initialize(line_details)
3
+ @line_details = line_details || []
4
+ end
5
+
6
+ def names
7
+ @names ||= @line_details.any? ? @line_details.last['lineIdentifier'] : []
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module LondonTransport
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: london_transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Wills
@@ -76,6 +76,8 @@ files:
76
76
  - lib/london_transport.rb
77
77
  - lib/london_transport/base.rb
78
78
  - lib/london_transport/bus.rb
79
+ - lib/london_transport/combined.rb
80
+ - lib/london_transport/line.rb
79
81
  - lib/london_transport/train.rb
80
82
  - lib/london_transport/tube.rb
81
83
  - lib/london_transport/version.rb