Class: TouristicObject
- Inherits:
-
Object
- Object
- TouristicObject
- 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- ASPECT_WINTER =
'HIVER'- ASPECT_SUMMER =
'ETE'- ASPECT_CHALLENGED =
'HANDICAP'- ASPECT_BUSINESS =
'TOURISME_AFFAIRES'- ASPECT_GROUPS =
'GROUPES'- ASPECT_ACTIVITIES =
'PRESTATAIRE_ACTIVITES'- PHONE =
201- EMAIL =
204- WEBSITE =
205- WEEKDAYS_FR =
['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']
Instance Method Summary collapse
- #accessibilite ⇒ Object
- #additional_criteria ⇒ Object
- #address ⇒ Object
- #address_details ⇒ Object
- #aspect_hash(all_fields, aspect_fields) ⇒ Object
- #bonplan ⇒ Object
- #contact(types_ids = []) ⇒ Object
- #cpltaccueil ⇒ Object
- #description ⇒ Object
- #details ⇒ Object
- #environments ⇒ Object
- #horaires ⇒ Object
- #id ⇒ Object
- #information ⇒ Object
-
#initialize(hash, aspect = nil) ⇒ TouristicObject
constructor
A new instance of TouristicObject.
- #latitude ⇒ Object
- #longitude ⇒ Object
- #multimedias ⇒ Object
- #open_day_predicate(opening_period) ⇒ Object
- #open_on?(start_date, end_date) ⇒ Boolean
- #pictures ⇒ Object
- #population ⇒ Object
- #prestations(prestation_type) ⇒ Object
- #ranges_intersect(ref_start_day, ref_end_day, other_start_day, other_end_day, ignore_year = false) ⇒ Object
- #resa ⇒ Object
- #reservation ⇒ Object
- #service_provider ⇒ Object
- #set_locale(locale) ⇒ Object
- #tarif ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
Methods included from AttributeHelper
Constructor Details
#initialize(hash, aspect = nil) ⇒ TouristicObject
Returns a new instance of TouristicObject.
47 48 49 50 51 52 53 54 55 |
# File 'lib/sitra_client/touristic_object.rb', line 47 def initialize(hash, aspect = nil) if aspect && hash[:aspects] aspect_data = hash[:aspects].select {|a| a[:aspect] == aspect && !a[:champsAspect].blank?}.first self.attributes = aspect_data ? aspect_hash(hash, aspect_data) : hash else self.attributes = hash end @libelle = DEFAULT_LIBELLE end |
Instance Method Details
#accessibilite ⇒ Object
254 255 256 |
# File 'lib/sitra_client/touristic_object.rb', line 254 def accessibilite @prestations && @prestations[:tourismesAdaptes] && @prestations[:tourismesAdaptes].collect {|t| t[@libelle]} end |
#additional_criteria ⇒ Object
224 225 226 |
# File 'lib/sitra_client/touristic_object.rb', line 224 def additional_criteria @presentation && @presentation[:typologiesPromoSitra] && @presentation[:typologiesPromoSitra].collect {|t| t[@libelle]} end |
#address ⇒ Object
144 145 146 147 148 |
# File 'lib/sitra_client/touristic_object.rb', line 144 def address computed_address = '' computed_address += "#{address_details[:adresse1]}, " unless address_details[:adresse1].nil? computed_address + address_details[:commune][:nom] end |
#address_details ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/sitra_client/touristic_object.rb', line 136 def address_details if @informationsActivite && @informationsActivite[:prestataireActivites] @informationsActivite[:prestataireActivites][:adresse] else @localisation[:adresse] end end |
#aspect_hash(all_fields, aspect_fields) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sitra_client/touristic_object.rb', line 57 def aspect_hash(all_fields, aspect_fields) all_data = all_fields.except(:aspects) aspect_data = aspect_fields.except(:aspect, :champsAspect) overrides = aspect_fields[:champsAspect] overrides.each do |o| path = o.split('.').map(&:to_sym) if all_data.dig(path.first, *path[1..-1]) && aspect_fields.dig(path.first, *path[1..-1]).nil? *keys, last_key = path keys.inject(all_data, :fetch)[last_key] = nil end end all_data.deep_merge(aspect_data) end |
#bonplan ⇒ Object
244 245 246 247 248 |
# File 'lib/sitra_client/touristic_object.rb', line 244 def bonplan if @presentation[:bonsPlans] @presentation[:bonsPlans][@libelle] || @presentation[:bonsPlans][DEFAULT_LIBELLE] end end |
#contact(types_ids = []) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sitra_client/touristic_object.rb', line 101 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
250 251 252 |
# File 'lib/sitra_client/touristic_object.rb', line 250 def cpltaccueil @prestations && @prestations[:complementAccueil] && @prestations[:complementAccueil][:libelleFr] end |
#description ⇒ Object
89 90 91 92 93 |
# File 'lib/sitra_client/touristic_object.rb', line 89 def description if @presentation[:descriptifCourt] @presentation[:descriptifCourt][@libelle] || @presentation[:descriptifCourt][DEFAULT_LIBELLE] end end |
#details ⇒ Object
95 96 97 98 99 |
# File 'lib/sitra_client/touristic_object.rb', line 95 def details if @presentation[:descriptifDetaille] @presentation[:descriptifDetaille][@libelle] || @presentation[:descriptifDetaille][DEFAULT_LIBELLE] end end |
#environments ⇒ Object
220 221 222 |
# File 'lib/sitra_client/touristic_object.rb', line 220 def environments @localisation && @localisation[:environnements] && @localisation[:environnements].collect {|e| e[@libelle]} end |
#horaires ⇒ Object
160 161 162 163 164 |
# File 'lib/sitra_client/touristic_object.rb', line 160 def horaires if @ouverture && @ouverture[:periodeEnClair] @ouverture[:periodeEnClair][@libelle] end end |
#id ⇒ Object
77 78 79 |
# File 'lib/sitra_client/touristic_object.rb', line 77 def id @id.to_s end |
#information ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/sitra_client/touristic_object.rb', line 113 def information specific_information = {} unless @type.nil? specific_information = instance_variable_get(SPECIFIC_INFOS[@type]) end @informations.merge(specific_information) end |
#latitude ⇒ Object
150 151 152 153 |
# File 'lib/sitra_client/touristic_object.rb', line 150 def latitude geoloc_details = parse_geoloc_details geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][1] : nil end |
#longitude ⇒ Object
155 156 157 158 |
# File 'lib/sitra_client/touristic_object.rb', line 155 def longitude geoloc_details = parse_geoloc_details geoloc_details[:valide] ? geoloc_details[:geoJson][:coordinates][0] : nil end |
#multimedias ⇒ Object
234 235 236 |
# File 'lib/sitra_client/touristic_object.rb', line 234 def multimedias @multimedias end |
#open_day_predicate(opening_period) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/sitra_client/touristic_object.rb', line 269 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
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/sitra_client/touristic_object.rb', line 166 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
121 122 123 124 |
# File 'lib/sitra_client/touristic_object.rb', line 121 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
195 196 197 198 199 200 201 |
# File 'lib/sitra_client/touristic_object.rb', line 195 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
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/sitra_client/touristic_object.rb', line 203 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
258 259 260 261 262 263 264 265 266 267 |
# File 'lib/sitra_client/touristic_object.rb', line 258 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
228 229 230 231 232 |
# File 'lib/sitra_client/touristic_object.rb', line 228 def resa if @reservation @reservation[:organismes] end end |
#reservation ⇒ Object
238 239 240 241 242 |
# File 'lib/sitra_client/touristic_object.rb', line 238 def reservation if @reservation[:complement] @reservation[:complement][:libelleFr] || @reservation[:complement][DEFAULT_LIBELLE] end end |
#service_provider ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/sitra_client/touristic_object.rb', line 126 def service_provider if @informationsActivite && @informationsActivite[:prestataireActivites] @informationsActivite[:prestataireActivites][:nom][@libelle] elsif @informationsFeteEtManifestation @informationsFeteEtManifestation[:nomLieu] else nil end end |
#set_locale(locale) ⇒ Object
71 72 73 74 75 |
# File 'lib/sitra_client/touristic_object.rb', line 71 def set_locale(locale) unless locale.nil? @libelle = "libelle#{locale.capitalize}".to_sym end end |
#tarif ⇒ Object
185 186 187 188 189 190 191 192 193 |
# File 'lib/sitra_client/touristic_object.rb', line 185 def tarif if @descriptionTarif if @descriptionTarif[:gratuit] return 'gratuit' elsif @descriptionTarif[:tarifsEnClair] @descriptionTarif[:tarifsEnClair][@libelle] end end end |
#title ⇒ Object
85 86 87 |
# File 'lib/sitra_client/touristic_object.rb', line 85 def title @nom[@libelle] || @nom[DEFAULT_LIBELLE] end |
#type ⇒ Object
81 82 83 |
# File 'lib/sitra_client/touristic_object.rb', line 81 def type @type end |