sitra_client 0.0.12 → 0.1.0

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/.gitignore CHANGED
@@ -1,17 +1,17 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in sitra_client.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sitra_client.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2014 jeanbaptistevilain
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2014 jeanbaptistevilain
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # SitraClient
2
-
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'sitra_client'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install sitra_client
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
1
+ # SitraClient
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sitra_client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sitra_client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.verbose = true
6
- t.pattern = '**/*_test.rb'
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.verbose = true
6
+ t.pattern = '**/*_test.rb'
7
7
  end
@@ -1,4 +1,7 @@
1
1
  # encoding: UTF-8
2
+ require 'active_support/duration'
3
+ require 'active_support/core_ext/numeric/time'
4
+ require 'active_support/core_ext/integer/time'
2
5
  require 'sitra_client/attribute_helper'
3
6
 
4
7
  class TouristicObject
@@ -30,6 +33,8 @@ class TouristicObject
30
33
  EMAIL = 204
31
34
  WEBSITE = 205
32
35
 
36
+ WEEKDAYS_FR = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']
37
+
33
38
  def initialize(hash)
34
39
  self.attributes = hash
35
40
  @libelle = DEFAULT_LIBELLE
@@ -129,6 +134,25 @@ class TouristicObject
129
134
  end
130
135
  end
131
136
 
137
+ def open_on?(start_date, end_date)
138
+ opening_periods = @ouverture[:periodesOuvertures]
139
+ is_open = false
140
+ unless opening_periods.nil? || opening_periods.empty?
141
+ i = 0
142
+ while !is_open && i < opening_periods.length
143
+ period_start = Date.parse(opening_periods[i][:dateDebut])
144
+ period_end = Date.parse(opening_periods[i][:dateFin])
145
+ start_day = Date.parse(start_date)
146
+ end_day = [Date.parse(end_date), start_day.next_month].min
147
+ if ranges_intersect(period_start, period_end, start_day, end_day, opening_periods[i][:tousLesAns])
148
+ is_open = (start_day..end_day).to_a.any? {|d| open_day_predicate(opening_periods[i]).call(d)}
149
+ end
150
+ i += 1
151
+ end
152
+ end
153
+ is_open
154
+ end
155
+
132
156
  def tarif
133
157
  if @descriptionTarif
134
158
  if @descriptionTarif[:gratuit]
@@ -149,21 +173,18 @@ class TouristicObject
149
173
 
150
174
  def prestations(prestation_type)
151
175
  presta = {}
152
- unless @prestations && @prestations[prestation_type].nil?
153
- @prestations && @prestations[prestation_type].each do |i|
154
- value = i[@libelle]
155
- if i[:familleCritere].nil?
156
- key = 'Autre'
157
- else
158
- key = i[:familleCritere][:libelleFr]
159
- end
160
- if presta.has_key?(key)
176
+ unless @prestations.nil? || @prestations[prestation_type].nil?
177
+ @prestations[prestation_type].each do |item|
178
+ value = item[@libelle]
179
+ if item[:familleCritere].nil?
180
+ key = 'Autre'
181
+ else
182
+ key = item[:familleCritere][:libelleFr]
183
+ end
184
+ presta[key] ||= []
161
185
  presta[key] << value
162
- else
163
- presta.store(key,[value])
164
186
  end
165
187
  end
166
- end
167
188
  presta
168
189
  end
169
190
 
@@ -205,8 +226,63 @@ class TouristicObject
205
226
  @prestations && @prestations[:tourismesAdaptes] && @prestations[:tourismesAdaptes].collect {|t| t[@libelle]}
206
227
  end
207
228
 
229
+ def ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, ignore_year = false)
230
+ has_intersection = other_start_day.between?(ref_start_day, ref_end_day) || other_end_day.between?(ref_start_day, ref_end_day) ||
231
+ ref_start_day.between?(other_start_day, other_end_day) || ref_end_day.between?(other_start_day, other_end_day)
232
+ if !has_intersection && ignore_year && ref_start_day <= other_end_day
233
+ ref_start_day = ref_start_day.next_year
234
+ ref_end_day = ref_end_day.next_year
235
+ has_intersection = ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, true)
236
+ end
237
+ has_intersection
238
+ end
239
+
240
+ def open_day_predicate(opening_period)
241
+ is_eligible = lambda {|date| return true}
242
+ case(opening_period[:type])
243
+ when 'OUVERTURE_SAUF'
244
+ excluded_days = opening_period[:ouverturesJournalieres].collect {|o| WEEKDAYS_FR.index(o[:jour].downcase)}
245
+ is_eligible = lambda {|date| return !excluded_days.include?(date.wday)}
246
+ when 'OUVERTURE_TOUS_LES_JOURS'
247
+ when 'OUVERTURE_SEMAINE'
248
+ unless opening_period[:ouverturesJournalieres][0][:jour] == 'TOUS'
249
+ included_days = opening_period[:ouverturesJournalieres].collect {|o| WEEKDAYS_FR.index(o[:jour].downcase)}
250
+ is_eligible = lambda {|date| return included_days.include?(date.wday)}
251
+ end
252
+ when 'OUVERTURE_MOIS'
253
+ opening_days = {}
254
+ unless opening_period[:ouverturesJourDuMois].nil?
255
+ opening_period[:ouverturesJourDuMois].each {|o| opening_days[o[:jour].downcase] = o[:jourDuMois]}
256
+ end
257
+ if opening_days.keys.include?('tous')
258
+ is_eligible = lambda {|date| return occurrence_in_month(date) == opening_days['tous']}
259
+ else
260
+ included_weekdays = opening_days.keys.collect {|d| WEEKDAYS_FR.index(d)}
261
+ is_eligible = lambda {|date| return included_weekdays.include?(date.wday) && occurrence_in_month(date) == opening_days[WEEKDAYS_FR[date.wday]]}
262
+ end
263
+ else
264
+ # Unsupported
265
+ end
266
+ is_eligible
267
+ end
268
+
208
269
  private
209
270
 
271
+ def occurrence_in_month(date)
272
+ case date.mday
273
+ when 1..7
274
+ 'D_1ER'
275
+ when 8..14
276
+ 'D_2EME'
277
+ when 15..21
278
+ 'D_3EME'
279
+ when 22..28
280
+ 'D_4EME'
281
+ else
282
+ 'D_DERNIER'
283
+ end
284
+ end
285
+
210
286
  def parse_geoloc_details
211
287
  if @informationsActivite.nil? || @informationsActivite[:commerceEtServicePrestataire].nil?
212
288
  geoloc_details = @localisation[:geolocalisation]
@@ -1,3 +1,3 @@
1
- module SitraClient
2
- VERSION = "0.0.12"
3
- end
1
+ module SitraClient
2
+ VERSION = "0.1.0"
3
+ end
data/lib/sitra_client.rb CHANGED
@@ -1,65 +1,65 @@
1
- require 'sitra_client/version'
2
- require 'sitra_client/sitra_query'
3
- require 'sitra_client/sitra_response'
4
- require 'open-uri'
5
- require 'logger'
6
-
7
- module SitraClient
8
-
9
- MAX_COUNT = 100
10
-
11
- # Safety net
12
- MAX_LOOPS = 5
13
-
14
- # Configuration defaults
15
- @config = {
16
- :base_url => 'http://api.sitra-tourisme.com/api/v001',
17
- :api_key => '',
18
- :site_identifier => ''
19
- }
20
-
21
- @valid_config_keys = @config.keys
22
- @logger = Logger.new(STDOUT)
23
-
24
- # Configure through hash
25
- def self.configure(opts = {})
26
- opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
27
- end
28
-
29
- def self.config
30
- @config
31
- end
32
-
33
- def self.query(criteria, all_results = false)
34
- if all_results
35
- loops = 0
36
- criteria[:first] = 0
37
- criteria[:count] = MAX_COUNT
38
- response = get_response(criteria)
39
- results = response.as_array
40
- while response.results_count > results.length && loops < MAX_LOOPS
41
- loops += 1
42
- criteria[:first] += MAX_COUNT
43
- results += get_response(criteria).as_array
44
- end
45
- else
46
- response = get_response(criteria)
47
- results = response.as_array
48
- end
49
- results
50
- end
51
-
52
- private
53
-
54
- def self.get_response(criteria)
55
- response = SitraResponse.new
56
- query = SitraQuery.new(@config[:api_key], @config[:site_identifier], criteria)
57
- @logger.info "Search query : #{@config[:base_url]}/recherche/list-objets-touristiques?query=#{query.to_params}"
58
- open("#{@config[:base_url]}/recherche/list-objets-touristiques?query=#{CGI.escape query.to_params}") { |f|
59
- f.each_line {|line| response.append_line(line)}
60
- }
61
- @logger.info "Retrieved #{response.returned_count} of #{response.results_count} results"
62
- response
63
- end
64
-
65
- end
1
+ require 'sitra_client/version'
2
+ require 'sitra_client/sitra_query'
3
+ require 'sitra_client/sitra_response'
4
+ require 'open-uri'
5
+ require 'logger'
6
+
7
+ module SitraClient
8
+
9
+ MAX_COUNT = 100
10
+
11
+ # Safety net
12
+ MAX_LOOPS = 5
13
+
14
+ # Configuration defaults
15
+ @config = {
16
+ :base_url => 'http://api.sitra-tourisme.com/api/v001',
17
+ :api_key => '',
18
+ :site_identifier => ''
19
+ }
20
+
21
+ @valid_config_keys = @config.keys
22
+ @logger = Logger.new(STDOUT)
23
+
24
+ # Configure through hash
25
+ def self.configure(opts = {})
26
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
27
+ end
28
+
29
+ def self.config
30
+ @config
31
+ end
32
+
33
+ def self.query(criteria, all_results = false)
34
+ if all_results
35
+ loops = 0
36
+ criteria[:first] = 0
37
+ criteria[:count] = MAX_COUNT
38
+ response = get_response(criteria)
39
+ results = response.as_array
40
+ while response.results_count > results.length && loops < MAX_LOOPS
41
+ loops += 1
42
+ criteria[:first] += MAX_COUNT
43
+ results += get_response(criteria).as_array
44
+ end
45
+ else
46
+ response = get_response(criteria)
47
+ results = response.as_array
48
+ end
49
+ results
50
+ end
51
+
52
+ private
53
+
54
+ def self.get_response(criteria)
55
+ response = SitraResponse.new
56
+ query = SitraQuery.new(@config[:api_key], @config[:site_identifier], criteria)
57
+ @logger.info "Search query : #{@config[:base_url]}/recherche/list-objets-touristiques?query=#{query.to_params}"
58
+ open("#{@config[:base_url]}/recherche/list-objets-touristiques?query=#{CGI.escape query.to_params}") { |f|
59
+ f.each_line {|line| response.append_line(line)}
60
+ }
61
+ @logger.info "Retrieved #{response.returned_count} of #{response.results_count} results"
62
+ response
63
+ end
64
+
65
+ end
data/sitra_client.gemspec CHANGED
@@ -1,27 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'sitra_client/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "sitra_client"
8
- spec.version = SitraClient::VERSION
9
- spec.authors = ["jeanbaptistevilain"]
10
- spec.email = ["jbvilain@gmail.com"]
11
- spec.description = "Sitra Client Gem"
12
- spec.summary = "A simple Ruby wrapper for the SITRA JSON api"
13
- spec.homepage = "https://github.com/jeanbaptistevilain/sitra_client"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.0"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "test-unit"
24
- spec.add_development_dependency "shoulda"
25
- spec.add_runtime_dependency "rails", "~> 3.2.14"
26
- spec.add_runtime_dependency "json"
27
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sitra_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sitra_client"
8
+ spec.version = SitraClient::VERSION
9
+ spec.authors = ["jeanbaptistevilain"]
10
+ spec.email = ["jbvilain@gmail.com"]
11
+ spec.description = "Sitra Client Gem"
12
+ spec.summary = "A simple Ruby wrapper for the SITRA JSON api"
13
+ spec.homepage = "https://github.com/jeanbaptistevilain/sitra_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.0"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "shoulda"
25
+ spec.add_runtime_dependency "rails", "~> 3.2.14"
26
+ spec.add_runtime_dependency "json"
27
+ end
@@ -129,7 +129,7 @@ class TouristicObjectTest < Test::Unit::TestCase
129
129
  hash_result = {:prestations => {:tourismesAdaptes => [{:libelleFr => "Accessible en fauteuil roulant en autonomie"}]}}
130
130
  touristic_object = TouristicObject.new(hash_result)
131
131
 
132
- assert_true touristic_object.prestations(:tourismesAdaptes).include?('Accessible en fauteuil roulant en autonomie')
132
+ assert_true touristic_object.prestations(:tourismesAdaptes).values[0].include?('Accessible en fauteuil roulant en autonomie')
133
133
  end
134
134
 
135
135
  should 'retrieve merged general and specific information' do
@@ -168,36 +168,161 @@ class TouristicObjectTest < Test::Unit::TestCase
168
168
  assert_equal 'my_description_en', touristic_object.description
169
169
  end
170
170
 
171
- should 'populate services data' do
172
-
173
- end
174
-
175
- should 'get key and value for criteria' do
176
-
177
- hash_result = { :services => [ {
178
- :libelleFr => "Accès autocar",
179
- :familleCritere => { :libelleFr => "Aide au client / transport" }
180
- },
181
- {
182
- :libelleFr => "Location de salles",
183
- :familleCritere => { :libelleFr => "Location / Prêt" }
184
- },
185
- {
186
- :libelleFr => "Pension complète",
187
- :familleCritere => { :libelleFr => "Formule d'hébergement" }
188
- },
189
- {
190
- :libelleFr => "Petit déjeuner en chambre",
191
- :familleCritere => { :libelleFr => "Formule d'hébergement" }
192
- },
193
- {
194
- :libelleFr => "Petit-déjeuner",
195
- :familleCritere => { :libelleFr => "Formule d'hébergement" }
196
- }]}
197
-
198
- touristic_object = TouristicObject.new(hash_result)
199
- resultat = touristic_object.prestations(:services)
200
- assert_equal "{}", resultat
201
- end
171
+ should 'return predicate covering openings every day of the week' do
172
+ opening_hash = {:type => 'OUVERTURE_TOUS_LES_JOURS'}
173
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
174
+
175
+ assert_equal true, predicate.call(Date.new(2015, 2, 8))
176
+ assert_equal true, predicate.call(Date.new(2015, 2, 9))
177
+ assert_equal true, predicate.call(Date.new(2015, 2, 10))
178
+ assert_equal true, predicate.call(Date.new(2015, 2, 11))
179
+ assert_equal true, predicate.call(Date.new(2015, 2, 12))
180
+ assert_equal true, predicate.call(Date.new(2015, 2, 13))
181
+ assert_equal true, predicate.call(Date.new(2015, 2, 14))
182
+ end
183
+
184
+ should 'return predicate covering openings all days of the week except one' do
185
+ opening_hash = {:type => 'OUVERTURE_SAUF', :ouverturesJournalieres => [{:jour => 'DIMANCHE'}]}
186
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
187
+
188
+ assert_equal false, predicate.call(Date.new(2015, 2, 8))
189
+ assert_equal true, predicate.call(Date.new(2015, 2, 9))
190
+ assert_equal true, predicate.call(Date.new(2015, 2, 10))
191
+ assert_equal true, predicate.call(Date.new(2015, 2, 11))
192
+ assert_equal true, predicate.call(Date.new(2015, 2, 12))
193
+ assert_equal true, predicate.call(Date.new(2015, 2, 13))
194
+ assert_equal true, predicate.call(Date.new(2015, 2, 14))
195
+ end
196
+
197
+ should 'return predicate covering openings only on specified days' do
198
+ opening_hash = {:type => 'OUVERTURE_SEMAINE', :ouverturesJournalieres => [{:jour => 'LUNDI'}, {:jour => 'MERCREDI'}, {:jour => 'VENDREDI'}]}
199
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
200
+
201
+ assert_equal false, predicate.call(Date.new(2015, 2, 8))
202
+ assert_equal true, predicate.call(Date.new(2015, 2, 9))
203
+ assert_equal false, predicate.call(Date.new(2015, 2, 10))
204
+ assert_equal true, predicate.call(Date.new(2015, 2, 11))
205
+ assert_equal false, predicate.call(Date.new(2015, 2, 12))
206
+ assert_equal true, predicate.call(Date.new(2015, 2, 13))
207
+ assert_equal false, predicate.call(Date.new(2015, 2, 14))
208
+ end
209
+
210
+ should 'return predicate covering all week days (alternative)' do
211
+ opening_hash = {:type => 'OUVERTURE_SEMAINE', :ouverturesJournalieres => [{:jour => 'TOUS'}]}
212
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
213
+
214
+ assert_equal true, predicate.call(Date.new(2015, 2, 8))
215
+ assert_equal true, predicate.call(Date.new(2015, 2, 9))
216
+ assert_equal true, predicate.call(Date.new(2015, 2, 10))
217
+ assert_equal true, predicate.call(Date.new(2015, 2, 11))
218
+ assert_equal true, predicate.call(Date.new(2015, 2, 12))
219
+ assert_equal true, predicate.call(Date.new(2015, 2, 13))
220
+ assert_equal true, predicate.call(Date.new(2015, 2, 14))
221
+ end
222
+
223
+ should 'return predicate covering opening on a specific day of the month' do
224
+ opening_hash = {:type => 'OUVERTURE_MOIS', :ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_2EME'}]}
225
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
226
+
227
+ assert_equal false, predicate.call(Date.new(2015, 2, 2))
228
+ assert_equal false, predicate.call(Date.new(2015, 2, 8))
229
+ assert_equal true, predicate.call(Date.new(2015, 2, 9))
230
+ assert_equal false, predicate.call(Date.new(2015, 2, 10))
231
+ assert_equal false, predicate.call(Date.new(2015, 2, 11))
232
+ assert_equal false, predicate.call(Date.new(2015, 2, 12))
233
+ assert_equal false, predicate.call(Date.new(2015, 2, 13))
234
+ assert_equal false, predicate.call(Date.new(2015, 2, 14))
235
+ assert_equal false, predicate.call(Date.new(2015, 2, 16))
236
+ end
202
237
 
238
+ should 'return predicate covering openings on several days of the month' do
239
+ opening_hash = {:type => 'OUVERTURE_MOIS',
240
+ :ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_4EME'}, {:jour => 'MARDI', :jourDuMois => 'D_1ER'}]}
241
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
242
+
243
+ assert_equal true, predicate.call(Date.new(2015, 2, 3))
244
+ assert_equal false, predicate.call(Date.new(2015, 2, 9))
245
+ assert_equal false, predicate.call(Date.new(2015, 2, 10))
246
+ assert_equal false, predicate.call(Date.new(2015, 2, 11))
247
+ assert_equal false, predicate.call(Date.new(2015, 2, 12))
248
+ assert_equal false, predicate.call(Date.new(2015, 2, 13))
249
+ assert_equal false, predicate.call(Date.new(2015, 2, 14))
250
+ assert_equal false, predicate.call(Date.new(2015, 2, 15))
251
+ assert_equal true, predicate.call(Date.new(2015, 2, 23))
252
+ end
253
+
254
+ should 'return predicate covering openings on the first week of the month' do
255
+ opening_hash = {:type => 'OUVERTURE_MOIS',
256
+ :ouverturesJourDuMois => [{:jour => 'TOUS', :jourDuMois => 'D_1ER'}]}
257
+ predicate = TouristicObject.new({}).open_day_predicate(opening_hash)
258
+
259
+ assert_equal true, predicate.call(Date.new(2015, 2, 1))
260
+ assert_equal true, predicate.call(Date.new(2015, 2, 2))
261
+ assert_equal true, predicate.call(Date.new(2015, 2, 3))
262
+ assert_equal true, predicate.call(Date.new(2015, 2, 4))
263
+ assert_equal true, predicate.call(Date.new(2015, 2, 5))
264
+ assert_equal true, predicate.call(Date.new(2015, 2, 6))
265
+ assert_equal true, predicate.call(Date.new(2015, 2, 7))
266
+ assert_equal false, predicate.call(Date.new(2015, 2, 8))
267
+ end
268
+
269
+ should 'detect date ranges intersection' do
270
+ touristic_object = TouristicObject.new({})
271
+
272
+ assert_equal false, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 1, 31), Date.new(2015, 2, 15), Date.new(2015, 2, 25))
273
+ assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 12, 31), Date.new(2015, 1, 15), Date.new(2015, 1, 25))
274
+ assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 1), Date.new(2015, 1, 31), Date.new(2015, 1, 15), Date.new(2015, 2, 5))
275
+ assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 20), Date.new(2015, 1, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 27))
276
+ assert_equal true, touristic_object.ranges_intersect(Date.new(2015, 1, 20), Date.new(2015, 1, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22))
277
+ assert_equal false, touristic_object.ranges_intersect(Date.new(2014, 1, 5), Date.new(2014, 12, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22), false)
278
+ assert_equal true, touristic_object.ranges_intersect(Date.new(2014, 1, 5), Date.new(2014, 12, 25), Date.new(2015, 1, 15), Date.new(2015, 1, 22), true)
279
+ assert_equal true, touristic_object.ranges_intersect(Date.new(2012, 12, 25), Date.new(2013, 1, 15), Date.new(2015, 1, 8), Date.new(2015, 1, 14), true)
280
+ end
281
+
282
+ should 'return opening status for date with a single opening period' do
283
+ opening_hash = {:ouverture => {
284
+ :periodesOuvertures => [
285
+ {:dateDebut => '2014-1-1',
286
+ :dateFin => '2014-12-31',
287
+ :tousLesAns => true,
288
+ :type => 'OUVERTURE_MOIS',
289
+ :ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_1ER'}]}
290
+ ]
291
+ }}
292
+ touristic_object = TouristicObject.new(opening_hash)
293
+
294
+ assert_equal true, touristic_object.open_on?('2015-2-2', '2015-2-2')
295
+ assert_equal true, touristic_object.open_on?('2015-2-1', '2015-2-5')
296
+ assert_equal true, touristic_object.open_on?('2015-3-1', '2015-3-10')
297
+ assert_equal true, touristic_object.open_on?('2016-3-1', '2016-3-10')
298
+ assert_equal false, touristic_object.open_on?('2015-2-9', '2015-2-9')
299
+ assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
300
+ end
301
+
302
+ should 'return opening status for date with multiple opening period' do
303
+ opening_hash = {:ouverture => {
304
+ :periodesOuvertures => [{:dateDebut => '2014-1-1',
305
+ :dateFin => '2014-12-31',
306
+ :tousLesAns => true,
307
+ :type => 'OUVERTURE_MOIS',
308
+ :ouverturesJourDuMois => [{:jour => 'LUNDI', :jourDuMois => 'D_1ER'}]},
309
+ {:dateDebut => '2015-1-1',
310
+ :dateFin => '2015-1-31',
311
+ :tousLesAns => false,
312
+ :type => 'OUVERTURE_SEMAINE',
313
+ :ouverturesJournalieres => [{:jour => 'LUNDI'}, {:jour => 'MARDI'}, {:jour => 'JEUDI'}]}]
314
+ }}
315
+ touristic_object = TouristicObject.new(opening_hash)
316
+
317
+ assert_equal true, touristic_object.open_on?('2015-2-2', '2015-2-2')
318
+ assert_equal true, touristic_object.open_on?('2015-2-1', '2015-2-5')
319
+ assert_equal true, touristic_object.open_on?('2015-3-1', '2015-3-10')
320
+ assert_equal true, touristic_object.open_on?('2016-3-1', '2016-3-10')
321
+ assert_equal true, touristic_object.open_on?('2015-1-5', '2016-1-5')
322
+ assert_equal true, touristic_object.open_on?('2015-1-12', '2015-1-12')
323
+ assert_equal true, touristic_object.open_on?('2015-1-6', '2015-1-16')
324
+ assert_equal true, touristic_object.open_on?('2015-1-8', '2015-1-8')
325
+ assert_equal false, touristic_object.open_on?('2015-2-9', '2015-2-9')
326
+ assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
327
+ end
203
328
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitra_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - jeanbaptistevilain
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-08-28 00:00:00.000000000 Z
12
+ date: 2015-02-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: test-unit
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: shoulda
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rails
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :runtime
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: json
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :runtime
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -119,26 +132,27 @@ files:
119
132
  homepage: https://github.com/jeanbaptistevilain/sitra_client
120
133
  licenses:
121
134
  - MIT
122
- metadata: {}
123
135
  post_install_message:
124
136
  rdoc_options: []
125
137
  require_paths:
126
138
  - lib
127
139
  required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
128
141
  requirements:
129
142
  - - ! '>='
130
143
  - !ruby/object:Gem::Version
131
144
  version: '0'
132
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
133
147
  requirements:
134
148
  - - ! '>='
135
149
  - !ruby/object:Gem::Version
136
150
  version: '0'
137
151
  requirements: []
138
152
  rubyforge_project:
139
- rubygems_version: 2.4.1
153
+ rubygems_version: 1.8.24
140
154
  signing_key:
141
- specification_version: 4
155
+ specification_version: 3
142
156
  summary: A simple Ruby wrapper for the SITRA JSON api
143
157
  test_files:
144
158
  - test/sitra_client/sitra_query_test.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjA3NmMzMWIwOTQ0ZTY0NjU4OTRhMjc4NGYyYjdhZjcwNjI2ZDIzOA==
5
- data.tar.gz: !binary |-
6
- OTEzNWZmNzZiNWE0ODgzZWM2YWFmNmIwZDYzYWFhZDY0ZTBiMTQ3NA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- Mjk5Mjg2YjRjY2RjOTEyNDQ5ODRkNTJiNjkzZmFhNTE2MGQxODljNTUxN2U3
10
- ZGI1MGE1N2YxMzY0NTFlZDcwMjQ5YzA1MGQ1NjJmMzMwNTMwOGUzMzc3YjIz
11
- MTc5ZThjMjk4OWZiZWM3MDAwNmRkZjdjNWVkMmI5MWIzYjY5Njg=
12
- data.tar.gz: !binary |-
13
- YjQzODhiYzQ4NjM5YTc5MTEwMzUzZWUyOTIxZTA4ZTcwNzY3NzZjZTVkODQ1
14
- ZThhMjMyYWM2ZDc2OGRkMDFhY2E3YTRlNDQ3OTBhMDVmZWVmZGM0MGY3ODBl
15
- NmVkZGVlMDQ3ZGJjYzQ2OWRjMzI4ZjI4ZjM5YjBmNmQ0OTRmMDc=