Class: TouristicObject

Inherits:
Object
  • Object
show all
Includes:
AttributeHelper
Defined in:
lib/sitra_client/touristic_object.rb

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

Methods included from AttributeHelper

#attributes, #attributes=

Constructor Details

#initialize(hash) ⇒ TouristicObject

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

#accessibiliteObject



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_criteriaObject



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

#addressObject



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_detailsObject



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

#bonplanObject



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

#contact(types_ids = []) ⇒ Object



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

#cpltaccueilObject



222
223
224
# File 'lib/sitra_client/touristic_object.rb', line 222

def cpltaccueil
  @prestations && @prestations[:complementAccueil] && @prestations[:complementAccueil][:libelleFr]
end

#descriptionObject



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

#detailsObject



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

#environmentsObject



192
193
194
# File 'lib/sitra_client/touristic_object.rb', line 192

def environments
  @localisation && @localisation[:environnements] && @localisation[:environnements].collect {|e| e[@libelle]}
end

#horairesObject



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

#idObject



49
50
51
# File 'lib/sitra_client/touristic_object.rb', line 49

def id
  @id.to_s
end

#informationObject



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

#latitudeObject



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

#longitudeObject



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

#multimediasObject



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
    # Unsupported
  end
  is_eligible
end

#open_on?(start_date, end_date) ⇒ Boolean

Returns:

  • (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

#picturesObject



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

#populationObject



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

#resaObject



200
201
202
203
204
# File 'lib/sitra_client/touristic_object.rb', line 200

def resa
  if @reservation
    @reservation[:organismes]
  end
end

#reservationObject



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_providerObject



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

#tarifObject



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

#titleObject



57
58
59
# File 'lib/sitra_client/touristic_object.rb', line 57

def title
  @nom[@libelle] || @nom[DEFAULT_LIBELLE]
end

#typeObject



53
54
55
# File 'lib/sitra_client/touristic_object.rb', line 53

def type
  @type
end