gares 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2ad3bf50a1a740e624ca06ba9ea4de2173b0b22
4
- data.tar.gz: 7e04564b13989559a80d666ce3d74717d1863ab9
3
+ metadata.gz: 371e96298472d334dcfbce42c20bc6a67813139a
4
+ data.tar.gz: 3dc98f7e626ed7d6092b912a8e3441047bffb0c3
5
5
  SHA512:
6
- metadata.gz: d1794901b7b8dc65826c3eb3fa07457798eccc6462828cda410c4d14fbff7062b49c6cfa85b8f5ef9cb7cf7b340378c68a688bf26ad66b52298ba834b194f92a
7
- data.tar.gz: e8b3bc039ff0b802dab7ee8ff1a81c60915774d275da36110d23db98ba01204cde0fcf8412a5708da63fb559ab8778e47fada48dcf1d97d028190e03f6d1f082
6
+ metadata.gz: 89a404991c7555b8c65ccfa57987f8e553b03f18c284be6a73536ab0ab3213e8060e32faafe29b2d4b8492c340d0ec8586ffe7cbf0b678ba8f71efe1485b69aa
7
+ data.tar.gz: a19cc680b00bc2244cf8670e0c60e60c91a92e75a0bade68004abc8adfc6f3c9e90a58000cc25700b0186629cbf0de49969162831c34a5caff3b9c48e40bccb9
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ rdoc/*
6
6
  Gemfile.lock
7
7
  .rvmrc
8
8
  .gh_pages
9
+ coverage/
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ group 'gem' do
2
+ guard 'rspec', :cmd => "bundle exec rspec", :all_on_start => false, :all_after_pass => false, :failed_mode => :focus do
3
+ watch(%r{^spec/.+_spec\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/gares/#{m[1]}_spec.rb" }
5
+ end
6
+ end
data/README.md CHANGED
@@ -1,23 +1,23 @@
1
- # Gares (en-mouvement)
1
+ # Gares - A gem to interact with French train Stations
2
2
 
3
3
  [![Build Status](https://travis-ci.org/paulRbr/gares.svg)](https://travis-ci.org/paulRbr/gares) [![Gem Version](https://badge.fury.io/rb/gares.svg)](http://badge.fury.io/rb/gares) [![Coverage Status](https://coveralls.io/repos/paulRbr/gares/badge.svg)](https://coveralls.io/r/paulRbr/gares)
4
4
 
5
5
  ## Description
6
6
 
7
- The Gares gem allows you to easy access publicly available data from gares-en-mouvement.com.
7
+ The Gares gem allows you to easily access publicly available data from gares-en-mouvement.com.
8
8
 
9
9
  ## Features
10
10
 
11
11
  Gares currently features the following:
12
12
 
13
- * Search for a gare
14
- * Retrieve gare information
13
+ * Search for a station
14
+ * Retrieve station information
15
15
 
16
16
  ## Examples
17
17
 
18
- ### Gare:
18
+ ### Station:
19
19
 
20
- g = Gares::Gare.new("frlpd")
20
+ g = Gares::Station.new("frlpd")
21
21
 
22
22
  g.name
23
23
  #=> "Lyon Part Dieu"
@@ -38,41 +38,41 @@ Gares currently features the following:
38
38
 
39
39
  g = Gares::Search.new("Aix")
40
40
 
41
- g.gares.size
41
+ g.stations.size
42
42
  #=> 7
43
43
 
44
44
  # or
45
45
 
46
- gares = Gares::Gare.search("lyon")
47
- gare = gares.last
46
+ stations = Gares::Station.search("lyon")
47
+ station = stations.last
48
48
 
49
- gare.name
49
+ station.name
50
50
  #=> "Paris Gare de Lyon"
51
51
 
52
52
  ## Installation
53
53
 
54
54
  gem install gares
55
55
 
56
- Or, if you're using this in a project with Bundler:
56
+ Or if you want to use it in a project add this to your `Gemfile`:
57
57
 
58
- gem gares
58
+ gem "gares"
59
59
 
60
60
  ## Running Tests
61
61
 
62
- As this gem uses content from gare-en-mouvement.com, the test suite uses a set of
63
- pre-defined fixute files in `spec/fixtures`. These fixtures are
64
- copies of gares-en-mouvement page used in tests.
62
+ As this gem uses external content from gare-en-mouvement.com and sncf.com, the test suite uses a set of
63
+ pre-defined fixture files in `spec/fixtures`. These fixtures are
64
+ copies of gares-en-mouvement.com and sncf.com pages used in tests.
65
65
 
66
66
  Run bundle install to install all dependencies, including fakeweb, which
67
- will serve the fixture files instead of doing actual requests to gares-en-mouvement.com.
67
+ will serve the fixture files instead of doing actual requests to gares-en-mouvement.com or sncf.com.
68
68
 
69
69
  $ bundle install
70
70
 
71
71
  Next, simple run `rake` to run the entire test suite.
72
72
 
73
- ### Running against actual gare-en-mouvement data
73
+ ### Running against real data
74
74
 
75
- It's possible to run the test suite directly against gares-en-mouvement.com. This has
75
+ It's possible to run the test suite directly against gares-en-mouvement.com or sncf.com. This has
76
76
  two disadvantages:
77
77
 
78
78
  1. Tests will be slow
@@ -80,7 +80,7 @@ two disadvantages:
80
80
 
81
81
  $ LIVE_TEST=true rake
82
82
 
83
- If you want to run against actual gares-en-mouvement data, it's better to just update
83
+ If you want to run against actual data, it's better to just update
84
84
  the fixture files once with up-to-date content:
85
85
 
86
86
  $ rake fixtures:refresh
@@ -92,12 +92,12 @@ When you run the test suite now, it will use the updated fixture files.
92
92
  Neither I, nor any developer who contributed to this project, accept any kind of
93
93
  liability for your use of this library.
94
94
 
95
- gares-en-mouvement does not permit use of its data by third parties without their consent.
95
+ gares-en-mouvement.com and sncf.com certainly does not permit use of its data by third parties without their consent.
96
96
 
97
97
  Using this library for anything other than limited personal use may result
98
- in an IP ban to the gares-en-mouvement website.
98
+ in an IP ban to the gares-en-mouvement.com or sncf.com website.
99
99
 
100
- _This gem is not endorsed or affiliated with gares-en-mouvement.com, or SNCF, Inc._
100
+ _This gem is not endorsed or affiliated with gares-en-mouvement.com, nor SNCF, Inc._
101
101
 
102
102
  ## License
103
103
 
data/lib/gares/base.rb CHANGED
@@ -6,13 +6,13 @@ module Gares
6
6
  GPS_COORD = 'Coordonnées GPS : '
7
7
  NAME = 'En direct de '
8
8
 
9
- # Initialize a new Gare object with it's gare-en-mouvemnt id (as a String)
9
+ # Initialize a new Station object with it's gare-en-mouvemnt id (as a String)
10
10
  #
11
- # gare = Gares::Gare.new("frabt")
11
+ # station = Gares::Station.new("frabt")
12
12
  #
13
- # Gares::Gare objects are lazy loading, meaning that no HTTP request
14
- # will be performed when a new object is created. Only when you use an
15
- # accessor that needs the remote data, a HTTP request is made (once).
13
+ # Gares::Station objects are lazy loaded, meaning that no HTTP request
14
+ # will be performed when a new object is created. An HTTP request is made (once)
15
+ # Only when you use an accessor that needs the remote data.
16
16
  #
17
17
  def initialize(slug, name = nil)
18
18
  @slug = slug
@@ -76,7 +76,7 @@ module Gares
76
76
 
77
77
  # Returns a new Nokogiri document for parsing.
78
78
  def document
79
- @document ||= Nokogiri::HTML(Gares::Gare.find_by_slug(@slug))
79
+ @document ||= Nokogiri::HTML(Gares::Station.find_by_slug(@slug))
80
80
  end
81
81
 
82
82
  # Use HTTParty to fetch the raw HTML for this gare.
@@ -86,7 +86,7 @@ module Gares
86
86
 
87
87
  # Convenience method for search
88
88
  def self.search(query)
89
- Gares::Search.new(query).gares
89
+ Gares::Search.new(query).stations
90
90
  end
91
- end # Gare
91
+ end # Base
92
92
  end # Gares
data/lib/gares/sales.rb CHANGED
@@ -9,7 +9,7 @@ module Gares
9
9
  private
10
10
 
11
11
  def document
12
- @document ||= Nokogiri::HTML(Gares::Gare.find_by_slug(
12
+ @document ||= Nokogiri::HTML(Gares::Station.find_by_slug(
13
13
  @slug, :"services-en-gare/vente/"))
14
14
  end
15
15
  end
data/lib/gares/search.rb CHANGED
@@ -1,25 +1,26 @@
1
1
  module Gares
2
- # Search Gares-en-mouvement for a gare name
3
- class Search < GareList
2
+ # Search Gares-en-mouvement for a station name
3
+ class Search < StationList
4
4
  attr_reader :query
5
5
 
6
+ # This is a file containing minimal information (name and slug) of all stations of gares-en-mouvement.com
6
7
  GARES_LIST_URL = "https://www.kimonolabs.com/api/7jys32dy?apikey=lsOO4tNm78cH9JxqWg9gAk9l4nYaou9j&kimmodify=1"
7
8
 
8
- # Initialize a new Gares search with the specified query
9
+ # Initialize a new Station search with the specified query
9
10
  #
10
11
  # search = Gares::Search.new("Aix")
11
12
  #
12
- # Gares::Search is lazy loading, meaning that unless you access the +gares+
13
- # attribute, no query is made to gares-en-mouvement.com.
13
+ # Gares::Search is lazy loaded, meaning that unless you access the +stations+
14
+ # attribute, no remomte query is made.
14
15
  #
15
16
  def initialize(query)
16
17
  @query = query
17
18
  end
18
19
 
19
- # Returns an array of Gares::Gare objects for easy search result yielded.
20
+ # Returns an array of Gares::Station objects in order to easily search result yielded.
20
21
  # If the +query+ was an exact match, a single element array will be returned.
21
- def gares
22
- @gares ||= (exact_match? ? parse_gare : parse_gares)
22
+ def stations
23
+ @stations ||= (exact_match? ? parse_station : parse_stations)
23
24
  end
24
25
 
25
26
  private
@@ -29,16 +30,18 @@ module Gares
29
30
  end
30
31
 
31
32
  def result
32
- @result ||= document.results.collection1.map(&:station).select { |gare| gare.name.to_ascii =~ /#{@query}/i }
33
+ @result ||= document.results.collection1.map(&:station).select do |station|
34
+ station.name.to_ascii =~ /#{@query.split(" ").join(".*")}/i
35
+ end
33
36
  end
34
37
 
35
38
  def self.query
36
39
  open(GARES_LIST_URL)
37
40
  end
38
41
 
39
- def parse_gare
40
- gare = result.first
41
- [Gares::Gare.new(gare.slug, gare.name)]
42
+ def parse_station
43
+ station = result.first
44
+ [Gares::Station.new(station.slug, station.name)]
42
45
  end
43
46
 
44
47
  def exact_match?
@@ -9,7 +9,7 @@ module Gares
9
9
  private
10
10
 
11
11
  def document
12
- @document ||= Nokogiri::HTML(Gares::Gare.find_by_slug(
12
+ @document ||= Nokogiri::HTML(Gares::Station.find_by_slug(
13
13
  @slug, :"services-en-gare/service/"))
14
14
  end
15
15
  end
@@ -0,0 +1,5 @@
1
+ module Gares
2
+ # Represents a station on gares-en-mouvement.com
3
+ class Station < Base
4
+ end # Station
5
+ end # Gares
@@ -0,0 +1,12 @@
1
+ module Gares
2
+ class StationList
3
+
4
+ private
5
+
6
+ def parse_stations
7
+ result.compact.uniq.map do |station|
8
+ Gares::Station.new(station.slug, station.name)
9
+ end
10
+ end
11
+ end # StationList
12
+ end # Gares
data/lib/gares/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gares
2
- VERSION = '0.1.4'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/gares.rb CHANGED
@@ -9,8 +9,8 @@ require 'hashie'
9
9
  require 'unidecoder'
10
10
 
11
11
  require 'gares/base'
12
- require 'gares/gare'
13
- require 'gares/gare_list'
12
+ require 'gares/station'
13
+ require 'gares/station_list'
14
14
  require 'gares/sales'
15
15
  require 'gares/services'
16
16
  require 'gares/search'
@@ -6,14 +6,13 @@ require 'spec_helper'
6
6
  #
7
7
  # http://www.gares-en-mouvement.com/fr/frlpd/votre-gare/
8
8
  #
9
-
10
- describe Gares::Gare do
9
+ describe Gares::Station do
11
10
 
12
11
  describe 'valid gare' do
13
12
 
14
13
  before(:each) do
15
14
  # Get gare de Lyon Part-Dieu
16
- @gare = Gares::Gare.new('frlpd')
15
+ @gare = Gares::Station.new('frlpd')
17
16
  end
18
17
 
19
18
  it 'should find the name' do
@@ -53,7 +52,7 @@ describe Gares::Gare do
53
52
  context 'a gare without wifi nor defibrillator' do
54
53
  before(:each) do
55
54
  # Get gare de Agde
56
- @gare = Gares::Gare.new('frxag')
55
+ @gare = Gares::Station.new('frxag')
57
56
  end
58
57
 
59
58
  it { expect(@gare.wifi?).to be(false) }
@@ -63,7 +62,7 @@ describe Gares::Gare do
63
62
  context 'a gare with no sales services' do
64
63
  before(:each) do
65
64
  # Get gare de Agde
66
- @gare = Gares::Gare.new('frxag')
65
+ @gare = Gares::Station.new('frxag')
67
66
  end
68
67
 
69
68
  it { expect(@gare.has_borne?).to be(false) }
@@ -73,7 +72,7 @@ describe Gares::Gare do
73
72
  describe 'with name that has utf-8 characters' do
74
73
  # Belleville sur Sâone
75
74
  before(:each) do
76
- @gare = Gares::Gare.search('Saone').first
75
+ @gare = Gares::Station.search('Saone').first
77
76
  end
78
77
 
79
78
  it 'should give the proper name' do
@@ -1,6 +1,6 @@
1
1
  describe Gares::Sales do
2
2
 
3
- context 'with a valid gare' do
3
+ context 'with a valid station' do
4
4
 
5
5
  subject(:sales) { Gares::Sales.new('frqxb') }
6
6
 
@@ -11,32 +11,45 @@ describe Gares::Search do
11
11
  end
12
12
 
13
13
  it 'should find 5 results' do
14
- expect(@search.gares.size).to eql(7)
14
+ expect(@search.stations.size).to eql(7)
15
15
  end
16
16
 
17
- it 'should return Gares::Gare objects only' do
18
- expect(@search.gares).to all(be_an(Gares::Gare))
17
+ it 'should return Gares::Station objects only' do
18
+ expect(@search.stations).to all(be_an(Gares::Station))
19
19
  end
20
20
 
21
21
  it 'should not return gares with no name' do
22
- @search.gares.each { |gare| expect(gare.name).to_not be_blank }
22
+ @search.stations.each { |gare| expect(gare.name).to_not be_blank }
23
23
  end
24
24
 
25
25
  it 'should return only the name of the result' do
26
- expect(@search.gares.first.name).to eql('Aix en Provence')
26
+ expect(@search.stations.first.name).to eql('Aix en Provence')
27
27
  end
28
28
  end
29
29
 
30
30
  context 'with an exact match' do
31
31
  it 'should not raise an exception' do
32
32
  expect do
33
- @search = Gares::Search.new('Paris Austerlitz').gares
33
+ @search = Gares::Search.new('Paris Austerlitz').stations
34
34
  end.not_to raise_error
35
35
  end
36
36
 
37
- it 'should return the movie slug correctly' do
37
+ it 'should return the gare slug correctly' do
38
38
  @search = Gares::Search.new('Paris Austerlitz')
39
- expect(@search.gares.first.slug).to eql('frpaz')
39
+ expect(@search.stations.first.slug).to eql('frpaz')
40
+ end
41
+ end
42
+
43
+ context 'with a fuzzy match' do
44
+ it 'should not raise an exception' do
45
+ expect do
46
+ @search = Gares::Search.new('CULMONT CHALINDREY').stations
47
+ end.not_to raise_error
48
+ end
49
+
50
+ it 'should return the gare slug correctly' do
51
+ @search = Gares::Search.new('CULMONT CHALINDREY')
52
+ expect(@search.stations.first.slug).to eql('frccy')
40
53
  end
41
54
  end
42
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Bonaud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -177,17 +177,18 @@ files:
177
177
  - ".rubocop_todo.yml"
178
178
  - ".travis.yml"
179
179
  - Gemfile
180
+ - Guardfile
180
181
  - MIT-LICENSE
181
182
  - README.md
182
183
  - Rakefile
183
184
  - gares.gemspec
184
185
  - lib/gares.rb
185
186
  - lib/gares/base.rb
186
- - lib/gares/gare.rb
187
- - lib/gares/gare_list.rb
188
187
  - lib/gares/sales.rb
189
188
  - lib/gares/search.rb
190
189
  - lib/gares/services.rb
190
+ - lib/gares/station.rb
191
+ - lib/gares/station_list.rb
191
192
  - lib/gares/string_extensions.rb
192
193
  - lib/gares/version.rb
193
194
  - spec/fixtures/frabt
data/lib/gares/gare.rb DELETED
@@ -1,5 +0,0 @@
1
- module Gares
2
- # Represents a Gare on gares-en-mouvement.com
3
- class Gare < Base
4
- end # Gare
5
- end # Gares
@@ -1,12 +0,0 @@
1
- module Gares
2
- class GareList
3
-
4
- private
5
-
6
- def parse_gares
7
- result.compact.uniq.map do |gare|
8
- Gares::Gare.new(gare.slug, gare.name)
9
- end
10
- end
11
- end # GareList
12
- end # Gares