easy_transilien 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96276f82ab18fe160b2ea7a3d6aad8ddbd6f127a
4
- data.tar.gz: f0b09fce59b88a9fbe295c78a9f79bdc8221bb65
3
+ metadata.gz: 3f38e80b6d65fc6f6036b5b5ec6fe55f328573f0
4
+ data.tar.gz: 639281a6923ea1021b1e3510988c2a52170e7606
5
5
  SHA512:
6
- metadata.gz: 82be3a630686b3cd01d7d65abb43f29bdb30c1543b25ca1f0b1e71ffa213ec6afbe68383eae3a1e5cda2e30ed7cb0febaacf48d81a873c1da3154676f45cd6e2
7
- data.tar.gz: 089ccc1c974e956b2c961881fd6b5d5639ccf06cb62297b923693eed0aecb14b69156c076c974cac05d74e928a7f440b29246a4dafd2c73e75c78f81a3686a0b
6
+ metadata.gz: da79f81f3bb47b36f461942d6ebd417f71200309dccce052cf0525833846199a70f57f8b9a4f168d4b71e8956ace737455397815d26f561fad5dfb6d243515ec
7
+ data.tar.gz: 7986a3e5d632b673ec70f6b4df56dc750ff53ab29cc145efe2722a009815d5c47252c6f847e6a3577c5029c29e20f5c190f5909e543545bf1189436ef65996ec
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_transilien (0.0.1)
5
- transilien_microservices (~> 0.0.3)
4
+ easy_transilien (0.0.2)
5
+ transilien_microservices (~> 0.0.5)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -55,7 +55,7 @@ GEM
55
55
  slop (3.4.6)
56
56
  thor (0.18.1)
57
57
  timers (1.1.0)
58
- transilien_microservices (0.0.3)
58
+ transilien_microservices (0.0.5)
59
59
  faraday (>= 0.8.4)
60
60
  nokogiri (>= 1.5.5)
61
61
  yard (0.8.7.2)
data/README.md CHANGED
@@ -56,6 +56,13 @@ trips = EasyTransilien::Trip.find('val d\'arg', 'paris sain', Time.local(now.yea
56
56
 
57
57
  Easy isn't it?
58
58
 
59
+ But you know, they are called Lines.
60
+
61
+ ```ruby
62
+ EasyTransilien::Line.find('J')
63
+ # => [<EasyTransilien... >]
64
+ ```
65
+
59
66
  ## Contributing
60
67
 
61
68
  1. Fork it
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.homepage = "https://github.com/ook/easy_transilien"
14
14
  gem.license = 'MIT'
15
15
 
16
- gem.add_runtime_dependency('transilien_microservices', '~> 0.0.3') # Hey, it's a wrapper, so we must wrap it ;)
16
+ gem.add_runtime_dependency('transilien_microservices', '~> 0.0.5') # Hey, it's a wrapper, so we must wrap it ;)
17
17
 
18
18
  gem.files = `git ls-files`.split($/)
19
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -0,0 +1,77 @@
1
+ module EasyTransilien
2
+ # ET::Line is NOT the translation of MS::Line
3
+ # It's the port of commercial names known by customers: "Ligne J", "Ligne L", etc.
4
+ # So, it's a collection of MS::Line, with (normally) a common MS::Network
5
+ class Line
6
+ attr_accessor :name, :access_time, :codes
7
+ attr_accessor :ms_network
8
+
9
+ class << self
10
+ def all_networks(options = {})
11
+ options[:force] ||= false
12
+ if options[:force] || @all_networks.nil?
13
+ @all_networks = ::Transilien::Network.find
14
+ end
15
+ @all_networks
16
+ end
17
+
18
+ def all_ms_lines(options = {})
19
+ options[:force] ||= false
20
+ if options[:force] || @all_ms_lines.nil?
21
+ @all_ms_lines = ::Transilien::Line.find
22
+ end
23
+ @all_ms_lines
24
+ end
25
+
26
+ # Find a line via a single letter (A,B,C,D,E,I,J,K,L, etc.)
27
+ def find(criterium = nil)
28
+ if criterium.is_a?(String)
29
+ regexp = /#{criterium}/i
30
+ matching = all_networks.reject { |n| n.name !~ regexp && n.external_code !~ regexp && !n.codes.map(&:downcase).include?(criterium.downcase) }
31
+ if matching.length == 1 # Ok, seems sucessful
32
+ return convert_networks_to_lines(matching)
33
+ end
34
+ elsif criterium.nil?
35
+ # No Args? Return everything.
36
+ return convert_networks_to_lines(all_networks)
37
+ else
38
+ raise "Can't understand #find criteria: not a letter, not nil, not a network line name: #{criterium.inspect}"
39
+ end
40
+ end
41
+
42
+ def convert_networks_to_lines(networks)
43
+ networks.map do |n|
44
+ item = new
45
+ item.name = n.name
46
+ item.access_time = n.access_time
47
+ item.ms_network = n
48
+ item.ms_lines << n.lines
49
+ item.ms_lines.compact!
50
+ item
51
+ end
52
+ end
53
+ end # << self
54
+
55
+ def line_external_codes
56
+ @lines_external_codes ||= begin
57
+ return nil unless ms_lines
58
+ ms_lines.map(&:external_code).sort.uniq
59
+ end
60
+ end
61
+
62
+ def codes
63
+ @codes ||= ms_lines.map(&:code).flatten.uniq.sort.reject { |code| code.length != 1 } # DEV NOTE lines with more than 1 letter are special lines for "travaux"
64
+ end
65
+
66
+ def ms_lines
67
+ @ms_lines ||= []
68
+ @ms_lines.flatten!
69
+ @ms_lines
70
+ end
71
+
72
+ def stations
73
+ @stations ||= EasyTransilien::Station.convert_stop_areas_to_stations(ms_lines.map { |ms_line| ms_line.stop_areas }.flatten.uniq)
74
+ end
75
+
76
+ end
77
+ end
@@ -1,6 +1,7 @@
1
1
  module EasyTransilien
2
2
  class Station
3
3
  attr_accessor :name, :external_code, :access_time
4
+ attr_accessor :ms_stop_area
4
5
 
5
6
  class << self
6
7
  # Get all available `Transilien::StopArea`
@@ -24,22 +25,44 @@ module EasyTransilien
24
25
  return convert_stop_areas_to_stations(matching)
25
26
  elsif criterium.is_a?(Station)
26
27
  return [criterium]
28
+ elsif criterium.is_a?(Hash)
29
+ matching = []
30
+ if criterium.keys.include?(:line_external_code)
31
+ all_stop_areas.select { |sa| raise sa.inspect }
32
+ end
33
+ return convert_stop_areas_to_stations(matching)
27
34
  elsif criterium.nil?
28
35
  return convert_stop_areas_to_stations(all_stop_areas)
36
+ else
37
+ raise 'WAZZUF?'
29
38
  end
30
39
  end
31
40
 
32
41
  def convert_stop_areas_to_stations(stop_areas)
33
42
  stop_areas.map do |sa|
34
43
  item = new
35
- item.name = sa.name
44
+ item.name = sa.name
36
45
  item.external_code = sa.external_code
37
- item.access_time = sa.access_time
46
+ item.access_time = sa.access_time
47
+ item.ms_stop_area = sa
38
48
  item
39
49
  end
40
50
  end
41
51
 
42
52
  end
53
+
54
+ def lines
55
+ @lines ||= EasyTransilien::Line.find()
56
+ end
57
+
58
+ def codes
59
+ @codes ||= ms_stop_area.lines.map(&:code).flatten.uniq.sort.reject { |c| c.length != 1 } # DEV NOTE lines with more than 1 letter are special lines for "travaux"
60
+ end
61
+
62
+ def coord(format = :gps)
63
+ if format == :gps
64
+ end
65
+ end
43
66
  end
44
67
 
45
68
  end
@@ -1,3 +1,3 @@
1
1
  module EasyTransilien
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -4,6 +4,7 @@ require "easy_transilien/version.rb"
4
4
  require "easy_transilien/stop.rb"
5
5
  require "easy_transilien/station.rb"
6
6
  require "easy_transilien/trip.rb"
7
+ require "easy_transilien/line.rb"
7
8
 
8
9
  module EasyTransilien
9
10
  end
data/spec/line_spec.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyTransilien::Line do
4
+ before(:each) do
5
+ @line = EasyTransilien::Line.find('laz').first
6
+ end
7
+
8
+ it 'should get some Line when searching for laz' do
9
+ @line.is_a?(EasyTransilien::Line).should be_true
10
+ end
11
+
12
+ it 'should have at least one codes' do
13
+ @line.codes.is_a?(Array).should be_true
14
+ @line.codes.empty?.should be_false
15
+ end
16
+ end
data/spec/station_spec.rb CHANGED
@@ -2,8 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe EasyTransilien::Station do
4
4
  it 'should get some Station when searching for argenteuil' do
5
- # This payload was generated from
6
- # http://ms.api.transilien.com/?action=VehicleJourneyList&RouteExternalCode=DUA8008540420003%3BDUA8008540430008%3BDUA8008540430010%3BDUA8008540430005%3BDUA8008544000030%3BDUA8008540440001|or&Date=2013|10|24&StartTime=18|19&EndTime=18|21
7
5
  col = EasyTransilien::Station.find('argenteuil')
8
6
  col.is_a?(Array).should be_true
9
7
  col.first.is_a?(EasyTransilien::Station).should be_true
@@ -14,4 +12,18 @@ describe EasyTransilien::Station do
14
12
  col.is_a?(Array).should be_true
15
13
  (col.length > 0).should be_true
16
14
  end
15
+
16
+ it 'should get Line for a Station' do
17
+ station = EasyTransilien::Station.find('Val d\'Argenteuil').first
18
+ station.lines.is_a?(Array).should be_true
19
+ station.lines[0].is_a?(EasyTransilien::Line).should be_true
20
+ end
21
+
22
+ it 'should get line_letters for a Station' do
23
+ station = EasyTransilien::Station.find('Val d\'Argenteuil').first
24
+ station.codes.is_a?(Array).should be_true
25
+ station.codes.length.should eq(1)
26
+ station.codes[0].is_a?(String).should be_true
27
+ station.codes[0].should eql('J')
28
+ end
17
29
  end
data/spec/trip_spec.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyTransilien::Trip do
4
+ before(:each) do
5
+ end
6
+
4
7
  it 'should get some Trip s from a simple search' do
5
8
  trips = EasyTransilien::Trip.find('val d\'argenteuil', 'paris saint-lazare')
6
9
  trips.first.is_a?(EasyTransilien::Trip).should be_true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_transilien
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Lecavelier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transilien_microservices
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.3
19
+ version: 0.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.3
26
+ version: 0.0.5
27
27
  description: 'Access SNCF Transilien micro-services datan the easy way: enable access
28
28
  to their theoric offer.'
29
29
  email:
@@ -43,10 +43,12 @@ files:
43
43
  - easy_transilien.gemspec
44
44
  - lib/easy_transilien.rb
45
45
  - lib/easy_transilien/easy.rb
46
+ - lib/easy_transilien/line.rb
46
47
  - lib/easy_transilien/station.rb
47
48
  - lib/easy_transilien/stop.rb
48
49
  - lib/easy_transilien/trip.rb
49
50
  - lib/easy_transilien/version.rb
51
+ - spec/line_spec.rb
50
52
  - spec/spec_helper.rb
51
53
  - spec/station_spec.rb
52
54
  - spec/stop_spec.rb
@@ -76,6 +78,7 @@ signing_key:
76
78
  specification_version: 4
77
79
  summary: See https://github.com/ook/easy_transilien
78
80
  test_files:
81
+ - spec/line_spec.rb
79
82
  - spec/spec_helper.rb
80
83
  - spec/station_spec.rb
81
84
  - spec/stop_spec.rb