Class: TouristicObject
Constant Summary
collapse
- SPECIFIC_INFOS =
{
'ACTIVITE' => '@informationsActivite',
'COMMERCE_ET_SERVICE' => '@informationsCommerceEtService',
'DEGUSTATION' => '@informationsDegustation',
'DOMAINE_SKIABLE' => '@informationsDomaineSkiable',
'EQUIPEMENT' => '@informationsEquipement',
'FETE_ET_MANIFESTATION' => '@informationsFeteEtManifestation',
'HEBERGEMENT_COLLECTIF' => '@informationsHebergementCollectif',
'HEBERGEMENT_LOCATIF' => '@informationsHebergementLocatif',
'HOTELLERIE' => '@informationsHotellerie',
'HOTELLERIE_PLEIN_AIR' => '@informationsHotelleriePleinAir',
'PATRIMOINE_CULTUREL' => '@informationsPatrimoineCulturel',
'PATRIMOINE_NATUREL' => '@informationsPatrimoineNaturel',
'RESTAURATION' => '@informationsRestauration',
'SEJOUR_PACKAGE' => '@informationsSejourPackage',
'STRUCTURE' => '@informationsStructure',
'TERRITOIRE' => '@informationsTerritoire'
}
- DEFAULT_LIBELLE =
:libelleFr
- PHONE =
201
- EMAIL =
204
- WEBSITE =
205
- WEEKDAYS_FR =
['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']
Instance Method Summary
collapse
#attributes, #attributes=
Constructor Details
Returns a new instance of TouristicObject.
38
39
40
41
|
# File 'lib/sitra_client/touristic_object.rb', line 38
def initialize(hash)
self.attributes = hash
@libelle = DEFAULT_LIBELLE
end
|
Instance Method Details
#accessibilite ⇒ Object
226
227
228
|
# File 'lib/sitra_client/touristic_object.rb', line 226
def accessibilite
@prestations && @prestations[:tourismesAdaptes] && @prestations[:tourismesAdaptes].collect {|t| t[@libelle]}
end
|
#additional_criteria ⇒ Object
196
197
198
|
# File 'lib/sitra_client/touristic_object.rb', line 196
def additional_criteria
@presentation && @presentation[:typologiesPromoSitra] && @presentation[:typologiesPromoSitra].collect {|t| t[@libelle]}
end
|
#address ⇒ Object
116
117
118
119
120
|
# File 'lib/sitra_client/touristic_object.rb', line 116
def address
computed_address = ''
computed_address += "#{address_details[:adresse1]}, " unless address_details[:adresse1].nil?
computed_address + address_details[:commune][:nom]
end
|
#address_details ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/sitra_client/touristic_object.rb', line 108
def address_details
if @informationsActivite && @informationsActivite[:prestataireActivites]
@informationsActivite[:prestataireActivites][:adresse]
else
@localisation[:adresse]
end
end
|
#bonplan ⇒ Object
216
217
218
219
220
|
# File 'lib/sitra_client/touristic_object.rb', line 216
def bonplan
if @presentation[:bonsPlans]
@presentation[:bonsPlans][@libelle] || @presentation[:bonsPlans][DEFAULT_LIBELLE]
end
end
|
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/sitra_client/touristic_object.rb', line 73
def contact(types_ids = [])
contact_details = {}
contact_entries = @informations[:moyensCommunication].nil? ? [] : @informations[:moyensCommunication]
contact_entries.each do |c|
if types_ids.include?(c[:type][:id])
label = c[:type][@libelle]
contact_details[label] = c[:coordonnees][:fr]
end
end
contact_details
end
|
#cpltaccueil ⇒ Object
222
223
224
|
# File 'lib/sitra_client/touristic_object.rb', line 222
def cpltaccueil
@prestations && @prestations[:complementAccueil] && @prestations[:complementAccueil][:libelleFr]
end
|
#description ⇒ Object
61
62
63
64
65
|
# File 'lib/sitra_client/touristic_object.rb', line 61
def description
if @presentation[:descriptifCourt]
@presentation[:descriptifCourt][@libelle] || @presentation[:descriptifCourt][DEFAULT_LIBELLE]
end
end
|
#details ⇒ Object
67
68
69
70
71
|
# File 'lib/sitra_client/touristic_object.rb', line 67
def details
if @presentation[:descriptifDetaille]
@presentation[:descriptifDetaille][@libelle] || @presentation[:descriptifDetaille][DEFAULT_LIBELLE]
end
end
|
#environments ⇒ Object
192
193
194
|
# File 'lib/sitra_client/touristic_object.rb', line 192
def environments
@localisation && @localisation[:environnements] && @localisation[:environnements].collect {|e| e[@libelle]}
end
|
#horaires ⇒ Object
132
133
134
135
136
|
# File 'lib/sitra_client/touristic_object.rb', line 132
def horaires
if @ouverture && @ouverture[:periodeEnClair]
@ouverture[:periodeEnClair][@libelle]
end
end
|
#id ⇒ Object
49
50
51
|
# File 'lib/sitra_client/touristic_object.rb', line 49
def id
@id.to_s
end
|
85
86
87
88
89
90
91
|
# File 'lib/sitra_client/touristic_object.rb', line 85
def information
specific_information = {}
unless @type.nil?
specific_information = instance_variable_get(SPECIFIC_INFOS[@type])
end
@informations.merge(specific_information)
end
|
#latitude ⇒ Object
122
123
124
125
|
# File 'lib/sitra_client/touristic_object.rb', line 122
def latitude
geoloc_details = parse_geoloc_details
geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][1] : nil
end
|
#longitude ⇒ Object
127
128
129
130
|
# File 'lib/sitra_client/touristic_object.rb', line 127
def longitude
geoloc_details = parse_geoloc_details
geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][0] : nil
end
|
206
207
208
|
# File 'lib/sitra_client/touristic_object.rb', line 206
def multimedias
@multimedias
end
|
#open_day_predicate(opening_period) ⇒ Object
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
|
# File 'lib/sitra_client/touristic_object.rb', line 241
def open_day_predicate(opening_period)
is_eligible = lambda {|date| return true}
case(opening_period[:type])
when 'OUVERTURE_SAUF'
excluded_days = opening_period[:ouverturesJournalieres].collect {|o| WEEKDAYS_FR.index(o[:jour].downcase)}
is_eligible = lambda {|date| return !excluded_days.include?(date.wday)}
when 'OUVERTURE_TOUS_LES_JOURS'
when 'OUVERTURE_SEMAINE'
unless opening_period[:ouverturesJournalieres][0][:jour] == 'TOUS'
included_days = opening_period[:ouverturesJournalieres].collect {|o| WEEKDAYS_FR.index(o[:jour].downcase)}
is_eligible = lambda {|date| return included_days.include?(date.wday)}
end
when 'OUVERTURE_MOIS'
opening_days = {}
unless opening_period[:ouverturesJourDuMois].nil?
opening_period[:ouverturesJourDuMois].each {|o| opening_days[o[:jour].downcase] = o[:jourDuMois]}
end
if opening_days.keys.include?('tous')
is_eligible = lambda {|date| return occurrence_in_month(date) == opening_days['tous']}
else
included_weekdays = opening_days.keys.collect {|d| WEEKDAYS_FR.index(d)}
is_eligible = lambda {|date| return included_weekdays.include?(date.wday) && occurrence_in_month(date) == opening_days[WEEKDAYS_FR[date.wday]]}
end
else
end
is_eligible
end
|
#open_on?(start_date, end_date) ⇒ Boolean
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/sitra_client/touristic_object.rb', line 138
def open_on?(start_date, end_date)
opening_periods = @ouverture[:periodesOuvertures]
is_open = false
unless opening_periods.nil? || opening_periods.empty?
i = 0
while !is_open && i < opening_periods.length
period_start = Date.parse(opening_periods[i][:dateDebut])
period_end = Date.parse(opening_periods[i][:dateFin])
start_day = Date.parse(start_date)
end_day = [Date.parse(end_date), start_day.next_month].min
if ranges_intersect(period_start, period_end, start_day, end_day, opening_periods[i][:tousLesAns])
is_open = (start_day..end_day).to_a.any? {|d| open_day_predicate(opening_periods[i]).call(d)}
end
i += 1
end
end
is_open
end
|
#pictures ⇒ Object
93
94
95
96
|
# File 'lib/sitra_client/touristic_object.rb', line 93
def pictures
(@illustrations.nil? || @illustrations.empty?) ? [{}] :
@illustrations.collect {|i| i[:traductionFichiers][0].keep_if {|k, v| k.to_s.start_with?('url')}}
end
|
#population ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/sitra_client/touristic_object.rb', line 167
def population
eligible_populations = []
if @prestations && @prestations[:typesClientele]
eligible_populations += @prestations[:typesClientele].collect {|t| t[@libelle]}
end
eligible_populations.uniq
end
|
#prestations(prestation_type) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/sitra_client/touristic_object.rb', line 175
def prestations(prestation_type)
presta = {}
unless @prestations.nil? || @prestations[prestation_type].nil?
@prestations[prestation_type].each do |item|
value = item[@libelle]
if item[:familleCritere].nil?
key = 'Autre'
else
key = item[:familleCritere][:libelleFr]
end
presta[key] ||= []
presta[key] << value
end
end
presta
end
|
#ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, ignore_year = false) ⇒ Object
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/sitra_client/touristic_object.rb', line 230
def ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, ignore_year = false)
has_intersection = other_start_day.between?(ref_start_day, ref_end_day) || other_end_day.between?(ref_start_day, ref_end_day) ||
ref_start_day.between?(other_start_day, other_end_day) || ref_end_day.between?(other_start_day, other_end_day)
if !has_intersection && ignore_year && ref_start_day <= other_end_day
ref_start_day = ref_start_day.next_year
ref_end_day = ref_end_day.next_year
has_intersection = ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, true)
end
has_intersection
end
|
#resa ⇒ Object
200
201
202
203
204
|
# File 'lib/sitra_client/touristic_object.rb', line 200
def resa
if @reservation
@reservation[:organismes]
end
end
|
#reservation ⇒ Object
210
211
212
213
214
|
# File 'lib/sitra_client/touristic_object.rb', line 210
def reservation
if @reservation[:complement]
@reservation[:complement][:libelleFr] || @reservation[:complement][DEFAULT_LIBELLE]
end
end
|
#service_provider ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/sitra_client/touristic_object.rb', line 98
def service_provider
if @informationsActivite && @informationsActivite[:prestataireActivites]
@informationsActivite[:prestataireActivites][:nom][@libelle]
elsif @informationsFeteEtManifestation
@informationsFeteEtManifestation[:nomLieu]
else
nil
end
end
|
#set_locale(locale) ⇒ Object
43
44
45
46
47
|
# File 'lib/sitra_client/touristic_object.rb', line 43
def set_locale(locale)
unless locale.nil?
@libelle = "libelle#{locale.capitalize}".to_sym
end
end
|
#tarif ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/sitra_client/touristic_object.rb', line 157
def tarif
if @descriptionTarif
if @descriptionTarif[:gratuit]
return 'gratuit'
elsif @descriptionTarif[:tarifsEnClair]
@descriptionTarif[:tarifsEnClair][@libelle]
end
end
end
|
#title ⇒ Object
57
58
59
|
# File 'lib/sitra_client/touristic_object.rb', line 57
def title
@nom[@libelle] || @nom[DEFAULT_LIBELLE]
end
|
#type ⇒ Object
53
54
55
|
# File 'lib/sitra_client/touristic_object.rb', line 53
def type
@type
end
|