sitra_client 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sitra_client.rb +4 -4
- data/lib/sitra_client/attribute_helper.rb +10 -10
- data/lib/sitra_client/sitra_query.rb +18 -18
- data/lib/sitra_client/sitra_response.rb +43 -43
- data/lib/sitra_client/touristic_object.rb +323 -295
- data/lib/sitra_client/version.rb +1 -1
- data/test/sitra_client/sitra_query_test.rb +15 -15
- data/test/sitra_client/sitra_response_test.rb +67 -67
- data/test/sitra_client/touristic_object_test.rb +381 -332
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710f4b61a67ff27a473ac6faf35646473c4a7b89
|
4
|
+
data.tar.gz: 711b7862fcf98031caded37dabe9481a3bc77180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a0f2683430e5a24393768fe6024999efdc911da418959b429c181699d0c50832c4c628c23e18d927c135102365d5062de7ab7aef1565d4c6de8435a4e2f55cf
|
7
|
+
data.tar.gz: 610ef251b9d0a64edabe28db915e28d6633fac269d58c548a8f77c28660b0070313c73c7fde647488b90b388015babc91734a3e6c21089c16ed60d4e2731768f
|
data/lib/sitra_client.rb
CHANGED
@@ -31,24 +31,24 @@ module SitraClient
|
|
31
31
|
@config
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.query(criteria, all_results = false)
|
34
|
+
def self.query(criteria, all_results = false, aspect = nil)
|
35
35
|
query_result = {}
|
36
36
|
if all_results
|
37
37
|
loops = 0
|
38
38
|
criteria[:first] = 0
|
39
39
|
criteria[:count] = MAX_COUNT
|
40
40
|
response = get_response(criteria)
|
41
|
-
results = response.as_array
|
41
|
+
results = response.as_array(aspect)
|
42
42
|
while response.results_count > results.length && loops < MAX_LOOPS
|
43
43
|
loops += 1
|
44
44
|
criteria[:first] += MAX_COUNT
|
45
|
-
results += get_response(criteria).as_array
|
45
|
+
results += get_response(criteria).as_array(aspect)
|
46
46
|
end
|
47
47
|
query_result[:count] = response.results_count
|
48
48
|
query_result[:results] = results
|
49
49
|
else
|
50
50
|
response = get_response(criteria)
|
51
|
-
results = response.as_array
|
51
|
+
results = response.as_array(aspect)
|
52
52
|
query_result[:count] = response.results_count
|
53
53
|
query_result[:results] = results
|
54
54
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module AttributeHelper
|
2
|
-
def attributes=(hash)
|
3
|
-
hash.each do |key, value|
|
4
|
-
instance_variable_set("@#{key}", value)
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def attributes
|
9
|
-
Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
|
10
|
-
end
|
1
|
+
module AttributeHelper
|
2
|
+
def attributes=(hash)
|
3
|
+
hash.each do |key, value|
|
4
|
+
instance_variable_set("@#{key}", value)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def attributes
|
9
|
+
Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
|
10
|
+
end
|
11
11
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'sitra_client/attribute_helper'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
class SitraQuery
|
5
|
-
|
6
|
-
include AttributeHelper
|
7
|
-
|
8
|
-
def initialize(api_key, site_identifier, criteria = {})
|
9
|
-
@apiKey = api_key
|
10
|
-
@projetId = site_identifier
|
11
|
-
self.attributes = criteria
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_params
|
15
|
-
JSON.generate attributes
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
1
|
+
require 'sitra_client/attribute_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class SitraQuery
|
5
|
+
|
6
|
+
include AttributeHelper
|
7
|
+
|
8
|
+
def initialize(api_key, site_identifier, criteria = {})
|
9
|
+
@apiKey = api_key
|
10
|
+
@projetId = site_identifier
|
11
|
+
self.attributes = criteria
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_params
|
15
|
+
JSON.generate attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,44 +1,44 @@
|
|
1
|
-
require 'sitra_client/attribute_helper'
|
2
|
-
require 'sitra_client/touristic_object'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
class SitraResponse
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@json_response = ''
|
9
|
-
@response_hash = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def append_line(line)
|
13
|
-
@json_response += line unless line.nil?
|
14
|
-
end
|
15
|
-
|
16
|
-
def returned_count
|
17
|
-
[as_hash[:query][:count], results_count - as_hash[:query][:first]].min
|
18
|
-
end
|
19
|
-
|
20
|
-
def results_count
|
21
|
-
as_hash[:numFound]
|
22
|
-
end
|
23
|
-
|
24
|
-
def as_hash
|
25
|
-
if @response_hash.empty?
|
26
|
-
@response_hash = JSON.parse @json_response, :symbolize_names => true
|
27
|
-
end
|
28
|
-
@response_hash
|
29
|
-
end
|
30
|
-
|
31
|
-
def as_raw_json
|
32
|
-
@json_response
|
33
|
-
end
|
34
|
-
|
35
|
-
def as_array
|
36
|
-
if as_hash[:objetsTouristiques].nil?
|
37
|
-
results = []
|
38
|
-
else
|
39
|
-
results = as_hash[:objetsTouristiques].collect {|obj_hash| TouristicObject.new(obj_hash)}
|
40
|
-
end
|
41
|
-
results
|
42
|
-
end
|
43
|
-
|
1
|
+
require 'sitra_client/attribute_helper'
|
2
|
+
require 'sitra_client/touristic_object'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class SitraResponse
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@json_response = ''
|
9
|
+
@response_hash = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def append_line(line)
|
13
|
+
@json_response += line unless line.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def returned_count
|
17
|
+
[as_hash[:query][:count], results_count - as_hash[:query][:first]].min
|
18
|
+
end
|
19
|
+
|
20
|
+
def results_count
|
21
|
+
as_hash[:numFound]
|
22
|
+
end
|
23
|
+
|
24
|
+
def as_hash
|
25
|
+
if @response_hash.empty?
|
26
|
+
@response_hash = JSON.parse @json_response, :symbolize_names => true
|
27
|
+
end
|
28
|
+
@response_hash
|
29
|
+
end
|
30
|
+
|
31
|
+
def as_raw_json
|
32
|
+
@json_response
|
33
|
+
end
|
34
|
+
|
35
|
+
def as_array(aspect = nil)
|
36
|
+
if as_hash[:objetsTouristiques].nil?
|
37
|
+
results = []
|
38
|
+
else
|
39
|
+
results = as_hash[:objetsTouristiques].collect {|obj_hash| TouristicObject.new(obj_hash, aspect)}
|
40
|
+
end
|
41
|
+
results
|
42
|
+
end
|
43
|
+
|
44
44
|
end
|
@@ -1,296 +1,324 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'active_support/duration'
|
3
|
-
require 'active_support/core_ext/
|
4
|
-
require 'active_support/core_ext/
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@
|
55
|
-
end
|
56
|
-
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
@
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
when
|
277
|
-
'
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'active_support/duration'
|
3
|
+
require 'active_support/core_ext/object/deep_dup'
|
4
|
+
require 'active_support/core_ext/hash/deep_merge'
|
5
|
+
require 'active_support/core_ext/numeric/time'
|
6
|
+
require 'active_support/core_ext/integer/time'
|
7
|
+
require 'sitra_client/attribute_helper'
|
8
|
+
|
9
|
+
class TouristicObject
|
10
|
+
|
11
|
+
include AttributeHelper
|
12
|
+
|
13
|
+
SPECIFIC_INFOS = {
|
14
|
+
'ACTIVITE' => '@informationsActivite',
|
15
|
+
'COMMERCE_ET_SERVICE' => '@informationsCommerceEtService',
|
16
|
+
'DEGUSTATION' => '@informationsDegustation',
|
17
|
+
'DOMAINE_SKIABLE' => '@informationsDomaineSkiable',
|
18
|
+
'EQUIPEMENT' => '@informationsEquipement',
|
19
|
+
'FETE_ET_MANIFESTATION' => '@informationsFeteEtManifestation',
|
20
|
+
'HEBERGEMENT_COLLECTIF' => '@informationsHebergementCollectif',
|
21
|
+
'HEBERGEMENT_LOCATIF' => '@informationsHebergementLocatif',
|
22
|
+
'HOTELLERIE' => '@informationsHotellerie',
|
23
|
+
'HOTELLERIE_PLEIN_AIR' => '@informationsHotelleriePleinAir',
|
24
|
+
'PATRIMOINE_CULTUREL' => '@informationsPatrimoineCulturel',
|
25
|
+
'PATRIMOINE_NATUREL' => '@informationsPatrimoineNaturel',
|
26
|
+
'RESTAURATION' => '@informationsRestauration',
|
27
|
+
'SEJOUR_PACKAGE' => '@informationsSejourPackage',
|
28
|
+
'STRUCTURE' => '@informationsStructure',
|
29
|
+
'TERRITOIRE' => '@informationsTerritoire'
|
30
|
+
}
|
31
|
+
|
32
|
+
DEFAULT_LIBELLE = :libelleFr
|
33
|
+
|
34
|
+
ASPECT_WINTER = 'HIVER'
|
35
|
+
ASPECT_SUMMER = 'ETE'
|
36
|
+
ASPECT_CHALLENGED = 'HANDICAP'
|
37
|
+
ASPECT_BUSINESS = 'TOURISME_AFFAIRES'
|
38
|
+
ASPECT_GROUPS = 'GROUPES'
|
39
|
+
ASPECT_ACTIVITIES = 'PRESTATAIRE_ACTIVITES'
|
40
|
+
|
41
|
+
PHONE = 201
|
42
|
+
EMAIL = 204
|
43
|
+
WEBSITE = 205
|
44
|
+
|
45
|
+
WEEKDAYS_FR = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']
|
46
|
+
|
47
|
+
def initialize(hash, aspect = nil)
|
48
|
+
if aspect && hash[:aspects]
|
49
|
+
aspect_data = hash[:aspects].select {|a| a[:aspect] == aspect && !a[:champsAspect].blank?}.first
|
50
|
+
self.attributes = aspect_data ? aspect_hash(hash, aspect_data) : hash
|
51
|
+
else
|
52
|
+
self.attributes = hash
|
53
|
+
end
|
54
|
+
@libelle = DEFAULT_LIBELLE
|
55
|
+
end
|
56
|
+
|
57
|
+
def aspect_hash(all_fields, aspect_fields)
|
58
|
+
all_data = all_fields.except(:aspects)
|
59
|
+
aspect_data = aspect_fields.except(:aspect, :champsAspect)
|
60
|
+
overrides = aspect_fields[:champsAspect]
|
61
|
+
overrides.each do |o|
|
62
|
+
path = o.split('.').map(&:to_sym)
|
63
|
+
if all_data.dig(path.first, *path[1..-1]) && aspect_fields.dig(path.first, *path[1..-1]).nil?
|
64
|
+
*keys, last_key = path
|
65
|
+
keys.inject(all_data, :fetch)[last_key] = nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
all_data.deep_merge(aspect_data)
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_locale(locale)
|
72
|
+
unless locale.nil?
|
73
|
+
@libelle = "libelle#{locale.capitalize}".to_sym
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def id
|
78
|
+
@id.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
def type
|
82
|
+
@type
|
83
|
+
end
|
84
|
+
|
85
|
+
def title
|
86
|
+
@nom[@libelle] || @nom[DEFAULT_LIBELLE]
|
87
|
+
end
|
88
|
+
|
89
|
+
def description
|
90
|
+
if @presentation[:descriptifCourt]
|
91
|
+
@presentation[:descriptifCourt][@libelle] || @presentation[:descriptifCourt][DEFAULT_LIBELLE]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def details
|
96
|
+
if @presentation[:descriptifDetaille]
|
97
|
+
@presentation[:descriptifDetaille][@libelle] || @presentation[:descriptifDetaille][DEFAULT_LIBELLE]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def contact(types_ids = [])
|
102
|
+
contact_details = {}
|
103
|
+
contact_entries = @informations[:moyensCommunication].nil? ? [] : @informations[:moyensCommunication]
|
104
|
+
contact_entries.each do |c|
|
105
|
+
if types_ids.include?(c[:type][:id])
|
106
|
+
label = c[:type][@libelle]
|
107
|
+
contact_details[label] = c[:coordonnees][:fr]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
contact_details
|
111
|
+
end
|
112
|
+
|
113
|
+
def information
|
114
|
+
specific_information = {}
|
115
|
+
unless @type.nil?
|
116
|
+
specific_information = instance_variable_get(SPECIFIC_INFOS[@type])
|
117
|
+
end
|
118
|
+
@informations.merge(specific_information)
|
119
|
+
end
|
120
|
+
|
121
|
+
def pictures
|
122
|
+
(@illustrations.nil? || @illustrations.empty?) ? [{}] :
|
123
|
+
@illustrations.collect {|i| i[:traductionFichiers][0].keep_if {|k, v| k.to_s.start_with?('url')}}
|
124
|
+
end
|
125
|
+
|
126
|
+
def service_provider
|
127
|
+
if @informationsActivite && @informationsActivite[:prestataireActivites]
|
128
|
+
@informationsActivite[:prestataireActivites][:nom][@libelle]
|
129
|
+
elsif @informationsFeteEtManifestation
|
130
|
+
@informationsFeteEtManifestation[:nomLieu]
|
131
|
+
else
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def address_details
|
137
|
+
if @informationsActivite && @informationsActivite[:prestataireActivites]
|
138
|
+
@informationsActivite[:prestataireActivites][:adresse]
|
139
|
+
else
|
140
|
+
@localisation[:adresse]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def address
|
145
|
+
computed_address = ''
|
146
|
+
computed_address += "#{address_details[:adresse1]}, " unless address_details[:adresse1].nil?
|
147
|
+
computed_address + address_details[:commune][:nom]
|
148
|
+
end
|
149
|
+
|
150
|
+
def latitude
|
151
|
+
geoloc_details = parse_geoloc_details
|
152
|
+
geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][1] : nil
|
153
|
+
end
|
154
|
+
|
155
|
+
def longitude
|
156
|
+
geoloc_details = parse_geoloc_details
|
157
|
+
geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][0] : nil
|
158
|
+
end
|
159
|
+
|
160
|
+
def horaires
|
161
|
+
if @ouverture && @ouverture[:periodeEnClair]
|
162
|
+
@ouverture[:periodeEnClair][@libelle]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def open_on?(start_date, end_date)
|
167
|
+
opening_periods = @ouverture[:periodesOuvertures]
|
168
|
+
is_open = false
|
169
|
+
unless opening_periods.nil? || opening_periods.empty?
|
170
|
+
i = 0
|
171
|
+
while !is_open && i < opening_periods.length
|
172
|
+
period_start = Date.parse(opening_periods[i][:dateDebut])
|
173
|
+
period_end = Date.parse(opening_periods[i][:dateFin])
|
174
|
+
start_day = Date.parse(start_date)
|
175
|
+
end_day = [Date.parse(end_date), start_day.next_month].min
|
176
|
+
if ranges_intersect(period_start, period_end, start_day, end_day, opening_periods[i][:tousLesAns])
|
177
|
+
is_open = (start_day..end_day).to_a.any? {|d| open_day_predicate(opening_periods[i]).call(d)}
|
178
|
+
end
|
179
|
+
i += 1
|
180
|
+
end
|
181
|
+
end
|
182
|
+
is_open
|
183
|
+
end
|
184
|
+
|
185
|
+
def tarif
|
186
|
+
if @descriptionTarif
|
187
|
+
if @descriptionTarif[:gratuit]
|
188
|
+
return 'gratuit'
|
189
|
+
elsif @descriptionTarif[:tarifsEnClair]
|
190
|
+
@descriptionTarif[:tarifsEnClair][@libelle]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def population
|
196
|
+
eligible_populations = []
|
197
|
+
if @prestations && @prestations[:typesClientele]
|
198
|
+
eligible_populations += @prestations[:typesClientele].collect {|t| t[@libelle]}
|
199
|
+
end
|
200
|
+
eligible_populations.uniq
|
201
|
+
end
|
202
|
+
|
203
|
+
def prestations(prestation_type)
|
204
|
+
presta = {}
|
205
|
+
unless @prestations.nil? || @prestations[prestation_type].nil?
|
206
|
+
@prestations[prestation_type].each do |item|
|
207
|
+
value = item[@libelle]
|
208
|
+
if item[:familleCritere].nil?
|
209
|
+
key = 'Autre'
|
210
|
+
else
|
211
|
+
key = item[:familleCritere][:libelleFr]
|
212
|
+
end
|
213
|
+
presta[key] ||= []
|
214
|
+
presta[key] << value
|
215
|
+
end
|
216
|
+
end
|
217
|
+
presta
|
218
|
+
end
|
219
|
+
|
220
|
+
def environments
|
221
|
+
@localisation && @localisation[:environnements] && @localisation[:environnements].collect {|e| e[@libelle]}
|
222
|
+
end
|
223
|
+
|
224
|
+
def additional_criteria
|
225
|
+
@presentation && @presentation[:typologiesPromoSitra] && @presentation[:typologiesPromoSitra].collect {|t| t[@libelle]}
|
226
|
+
end
|
227
|
+
|
228
|
+
def resa
|
229
|
+
if @reservation
|
230
|
+
@reservation[:organismes]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def multimedias
|
235
|
+
@multimedias
|
236
|
+
end
|
237
|
+
|
238
|
+
def reservation
|
239
|
+
if @reservation[:complement]
|
240
|
+
@reservation[:complement][:libelleFr] || @reservation[:complement][DEFAULT_LIBELLE]
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def bonplan
|
245
|
+
if @presentation[:bonsPlans]
|
246
|
+
@presentation[:bonsPlans][@libelle] || @presentation[:bonsPlans][DEFAULT_LIBELLE]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def cpltaccueil
|
251
|
+
@prestations && @prestations[:complementAccueil] && @prestations[:complementAccueil][:libelleFr]
|
252
|
+
end
|
253
|
+
|
254
|
+
def accessibilite
|
255
|
+
@prestations && @prestations[:tourismesAdaptes] && @prestations[:tourismesAdaptes].collect {|t| t[@libelle]}
|
256
|
+
end
|
257
|
+
|
258
|
+
def ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, ignore_year = false)
|
259
|
+
has_intersection = other_start_day.between?(ref_start_day, ref_end_day) || other_end_day.between?(ref_start_day, ref_end_day) ||
|
260
|
+
ref_start_day.between?(other_start_day, other_end_day) || ref_end_day.between?(other_start_day, other_end_day)
|
261
|
+
if !has_intersection && ignore_year && ref_start_day <= other_end_day
|
262
|
+
ref_start_day = ref_start_day.next_year
|
263
|
+
ref_end_day = ref_end_day.next_year
|
264
|
+
has_intersection = ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, true)
|
265
|
+
end
|
266
|
+
has_intersection
|
267
|
+
end
|
268
|
+
|
269
|
+
def open_day_predicate(opening_period)
|
270
|
+
is_eligible = lambda {|date| return true}
|
271
|
+
case(opening_period[:type])
|
272
|
+
when 'OUVERTURE_SAUF'
|
273
|
+
excluded_days = opening_period[:ouverturesJournalieres].collect {|o| WEEKDAYS_FR.index(o[:jour].downcase)}
|
274
|
+
is_eligible = lambda {|date| return !excluded_days.include?(date.wday)}
|
275
|
+
when 'OUVERTURE_TOUS_LES_JOURS'
|
276
|
+
when 'OUVERTURE_SEMAINE'
|
277
|
+
unless opening_period[:ouverturesJournalieres][0][:jour] == 'TOUS'
|
278
|
+
included_days = opening_period[:ouverturesJournalieres].collect {|o| WEEKDAYS_FR.index(o[:jour].downcase)}
|
279
|
+
is_eligible = lambda {|date| return included_days.include?(date.wday)}
|
280
|
+
end
|
281
|
+
when 'OUVERTURE_MOIS'
|
282
|
+
opening_days = {}
|
283
|
+
unless opening_period[:ouverturesJourDuMois].nil?
|
284
|
+
opening_period[:ouverturesJourDuMois].each {|o| opening_days[o[:jour].downcase] = o[:jourDuMois]}
|
285
|
+
end
|
286
|
+
if opening_days.keys.include?('tous')
|
287
|
+
is_eligible = lambda {|date| return occurrence_in_month(date) == opening_days['tous']}
|
288
|
+
else
|
289
|
+
included_weekdays = opening_days.keys.collect {|d| WEEKDAYS_FR.index(d)}
|
290
|
+
is_eligible = lambda {|date| return included_weekdays.include?(date.wday) && occurrence_in_month(date) == opening_days[WEEKDAYS_FR[date.wday]]}
|
291
|
+
end
|
292
|
+
else
|
293
|
+
# Unsupported
|
294
|
+
end
|
295
|
+
is_eligible
|
296
|
+
end
|
297
|
+
|
298
|
+
private
|
299
|
+
|
300
|
+
def occurrence_in_month(date)
|
301
|
+
case date.mday
|
302
|
+
when 1..7
|
303
|
+
'D_1ER'
|
304
|
+
when 8..14
|
305
|
+
'D_2EME'
|
306
|
+
when 15..21
|
307
|
+
'D_3EME'
|
308
|
+
when 22..28
|
309
|
+
'D_4EME'
|
310
|
+
else
|
311
|
+
'D_DERNIER'
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def parse_geoloc_details
|
316
|
+
if @informationsActivite.nil? || @informationsActivite[:prestataireActivites].nil?
|
317
|
+
geoloc_details = @localisation[:geolocalisation]
|
318
|
+
else
|
319
|
+
geoloc_details = @informationsActivite[:prestataireActivites][:geolocalisation]
|
320
|
+
end
|
321
|
+
geoloc_details
|
322
|
+
end
|
323
|
+
|
296
324
|
end
|