Class: Apidae::ApidaeDataParser
- Inherits:
-
Object
- Object
- Apidae::ApidaeDataParser
- Defined in:
- app/models/apidae/apidae_data_parser.rb
Constant Summary collapse
- PHONE =
201- ALT_PHONE =
206- EMAIL =
204- WEBSITE =
205- GOOGLE =
3789- FACEBOOK =
207- TWITTER =
3755- YELP =
4007- TRIP_ADVISOR =
4000- FAX =
202- MOBILE_WEBSITE =
3769- SHORTY_URL =
4923- INSTAGRAM =
7221- CONTACTS_MAP =
{ 'telephone' => PHONE, 'email' => EMAIL, 'website' => WEBSITE, 'facebook' => FACEBOOK, 'google' => GOOGLE, 'trip_advisor' => TRIP_ADVISOR, 'twitter' => TWITTER, 'yelp' => YELP, 'fax' => FAX, 'mobile_website' => MOBILE_WEBSITE, 'shorty_url' => SHORTY_URL, 'instagram' => INSTAGRAM }
- MODE_AUTO =
'auto'- MODE_MANUAL =
'manual'- MONDAY =
'MON'- TUESDAY =
'TUE'- WEDNESDAY =
'WED'- THURSDAY =
'THU'- FRIDAY =
'FRI'- SATURDAY =
'SAT'- SUNDAY =
'SUN'- ALL_DAYS =
[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
- WEEKDAYS_MAP =
{ 'LUNDI' => MONDAY, 'MARDI' => TUESDAY, 'MERCREDI' => WEDNESDAY, 'JEUDI' => THURSDAY, 'VENDREDI' => FRIDAY, 'SAMEDI' => SATURDAY, 'DIMANCHE' => SUNDAY }
Class Method Summary collapse
- .build_openings(openings_data, *locales) ⇒ Object
- .build_rate(rate_period, *locales) ⇒ Object
- .build_time_periods(o) ⇒ Object
- .compute_weekdays(opening_data) ⇒ Object
- .lists_ids(*lists) ⇒ Object
- .localized_key(loc = DEFAULT_LOCALE) ⇒ Object
- .localized_value(node, key, loc) ⇒ Object
- .node_id(node, key) ⇒ Object
- .node_value(node, key, *locales) ⇒ Object
- .nodes_ids(*nodes) ⇒ Object
- .parse_attachments_data(attachments_array, *locales) ⇒ Object
- .parse_booking(reservation_hash, visits_hash, *locales) ⇒ Object
- .parse_contact_data(information_hash, contacts_list) ⇒ Object
- .parse_desc_data(data_hash, private_data, presta_data, *locales) ⇒ Object
- .parse_entity_fields(information_hash, type_data_hash, sp_hash) ⇒ Object
- .parse_location_data(location_hash, type_data_hash, territories) ⇒ Object
-
.parse_openings(openings_hash, opening_days, *locales) ⇒ Object
Note : use internal format for openings storage (ideally Apihours one, to merge data from both sources).
- .parse_owner_data(data_hash, polls_data) ⇒ Object
- .parse_pictures_data(pictures_array, *locales) ⇒ Object
- .parse_rates(rates_hash, *locales) ⇒ Object
- .parse_service_data(data_hash, type_data_hash) ⇒ Object
- .parse_tags_data(pres_data_hash, crit_data_hash, linked_data_hash) ⇒ Object
- .parse_title(data_hash, *locales) ⇒ Object
- .parse_town(location_hash) ⇒ Object
- .parse_type_data(apidae_obj, type_hash, presta_hash, business_hash, ratings_list, *locales) ⇒ Object
- .parse_versioned_fields(data_hash) ⇒ Object
Class Method Details
.build_openings(openings_data, *locales) ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'app/models/apidae/apidae_data_parser.rb', line 394 def self.build_openings(openings_data, *locales) openings_list = openings_data[:periodesOuvertures] closing_days = openings_data[:fermeturesExceptionnelles] if openings_list.blank? [] else openings_list.map do |o| { id: o[:identifiant], external_id: o[:identifiantTechnique], start_date: o[:dateDebut], end_date: o[:dateFin], each_year: o[:tousLesAns], closing_days: closing_days.blank? ? [] : closing_days.map {|d| d[:dateSpeciale]}, details: node_value(o, :complementHoraire, *locales), time_periods: build_time_periods(o) } end end end |
.build_rate(rate_period, *locales) ⇒ Object
387 388 389 390 391 392 |
# File 'app/models/apidae/apidae_data_parser.rb', line 387 def self.build_rate(rate_period, *locales) { id: rate_period[:identifiant], start_date: rate_period[:dateDebut], end_date: rate_period[:dateFin], values: rate_period[:tarifs].blank? ? [] : rate_period[:tarifs].map {|t| {min: t[:minimum], max: t[:maximum], unit: t[:devise], type: t[:type][:id], details: node_value(t, :precisionTarif, *locales)}} } end |
.build_time_periods(o) ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'app/models/apidae/apidae_data_parser.rb', line 428 def self.build_time_periods(o) if o[:horaires].blank? [ { type: 'opening', weekdays: compute_weekdays(o), time_frames: (o[:horaireOuverture].blank? && o[:horaireFermeture].blank?) ? [] : [{start_time: o[:horaireOuverture], end_time: o[:horaireFermeture], recurrence: nil}] } ] else o[:horaires].map do |h| { type: h.dig(:type, :externalType), weekdays: compute_weekdays(o), time_frames: (h[:timePeriods] || []).map {|tp| (tp[:timeFrames] || [])}.flatten.select {|tf| !tf[:startTime].blank? || !tf[:endTime].blank?} .map {|tf| {start_time: tf[:startTime], end_time: tf[:endTime]}} } end end end |
.compute_weekdays(opening_data) ⇒ Object
415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'app/models/apidae/apidae_data_parser.rb', line 415 def self.compute_weekdays(opening_data) if opening_data[:type] == 'OUVERTURE_TOUS_LES_JOURS' ALL_DAYS elsif opening_data[:type] == 'OUVERTURE_SAUF' && opening_data[:ouverturesJournalieres] closed_weekdays = opening_data[:ouverturesJournalieres].map {|d| WEEKDAYS_MAP[d[:jour]]} ALL_DAYS - closed_weekdays elsif opening_data[:type] == 'OUVERTURE_SEMAINE' && opening_data[:ouverturesJournalieres] opening_data[:ouverturesJournalieres].map {|d| WEEKDAYS_MAP[d[:jour]]} else [] end end |
.lists_ids(*lists) ⇒ Object
467 468 469 |
# File 'app/models/apidae/apidae_data_parser.rb', line 467 def self.lists_ids(*lists) lists.blank? ? [] : lists.map {|l| l.blank? ? [] : l.map {|elt| elt[:id]}}.flatten.uniq end |
.localized_key(loc = DEFAULT_LOCALE) ⇒ Object
475 476 477 |
# File 'app/models/apidae/apidae_data_parser.rb', line 475 def self.localized_key(loc = DEFAULT_LOCALE) "libelle#{loc.camelize.gsub('-', '')}".to_sym end |
.localized_value(node, key, loc) ⇒ Object
459 460 461 462 463 464 465 |
# File 'app/models/apidae/apidae_data_parser.rb', line 459 def self.localized_value(node, key, loc) if node && node[key] node[key][localized_key(loc)] else '' end end |
.node_id(node, key) ⇒ Object
377 378 379 380 381 382 383 |
# File 'app/models/apidae/apidae_data_parser.rb', line 377 def self.node_id(node, key) if node && node[key] node[key].is_a?(Array) ? node[key][0][:id] : node[key][:id] else nil end end |
.node_value(node, key, *locales) ⇒ Object
449 450 451 452 453 454 455 456 457 |
# File 'app/models/apidae/apidae_data_parser.rb', line 449 def self.node_value(node, key, *locales) l = locales.blank? ? [DEFAULT_LOCALE] : locales locales_map = Hash[l.map {|loc| [localized_key(loc), loc]}] if node && node[key] node[key].slice(*locales_map.keys).transform_keys {|k| locales_map[k]} else {} end end |
.nodes_ids(*nodes) ⇒ Object
471 472 473 |
# File 'app/models/apidae/apidae_data_parser.rb', line 471 def self.nodes_ids(*nodes) nodes.blank? ? [] : nodes.select {|n| !n.blank?}.map {|n| n[:id]} end |
.parse_attachments_data(attachments_array, *locales) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/apidae/apidae_data_parser.rb', line 153 def self.(, *locales) atts_data = {} unless .blank? l = locales.blank? ? [DEFAULT_LOCALE] : locales l.each do |locale| atts_data[locale] = [] .select { |att| att.is_a?(Hash) && !att[:traductionFichiers].blank? }.each do |att| atts_data[locale] << { id: att[:identifiant], name: localized_value(att, :nom, locale), url: att[:traductionFichiers][0][:url].gsub('http:', 'https:'), type: att[:type], link: att[:link], description: localized_value(att, :legende, locale) } end end end {attachments: atts_data} end |
.parse_booking(reservation_hash, visits_hash, *locales) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'app/models/apidae/apidae_data_parser.rb', line 331 def self.parse_booking(reservation_hash, visits_hash, *locales) booking_hash = {} if reservation_hash booking_hash[:booking_desc] = node_value(reservation_hash, :complement, *locales) booking_hash[:booking_entities] = reservation_hash[:organismes] end if visits_hash booking_hash[:visits_allowed] = visits_hash[:visitable] == true booking_hash[:visits_desc] = node_value(visits_hash, :complementVisite, *locales) booking_hash[:visits_duration] = visits_hash[:dureeMoyenneVisiteIndividuelle] booking_hash[:visits_services] = lists_ids(visits_hash[:prestationsVisitesGroupees]) + lists_ids(visits_hash[:prestationsVisitesIndividuelles]) end booking_hash end |
.parse_contact_data(information_hash, contacts_list) ⇒ Object
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 |
# File 'app/models/apidae/apidae_data_parser.rb', line 174 def self.parse_contact_data(information_hash, contacts_list) contact_details = {contacts: contacts_list} unless information_hash.blank? contact_entries = information_hash[:moyensCommunication] || [] contact_entries.each do |c| case c[:type][:id] when PHONE, ALT_PHONE contact_details[:telephone] ||= {} contact_details[:telephone][c[:identifiant]] = { value: c.dig(:coordonnees, :fr), description: c.dig(:observation, :libelleFr), locales: Hash[(c[:coordonnees] || {}).except(:fr).keys.map {|l| [l, {value: c.dig(:coordonnees, l), description: c.dig(:observation, localized_key(l.to_s))}]}] } else contacts_refs_by_code = CONTACTS_MAP.invert if contacts_refs_by_code.keys.include?(c[:type][:id]) contact_ref = contacts_refs_by_code[c[:type][:id]].to_sym contact_details[contact_ref] ||= {} contact_details[contact_ref][c[:identifiant]] = { value: c.dig(:coordonnees, :fr), description: c.dig(:observation, :libelleFr), locales: Hash[(c[:coordonnees] || {}).except(:fr).keys.map {|l| [l, {value: c.dig(:coordonnees, l), description: c.dig(:observation, localized_key(l.to_s))}]}] } end end end end contact_details end |
.parse_desc_data(data_hash, private_data, presta_data, *locales) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/models/apidae/apidae_data_parser.rb', line 117 def self.parse_desc_data(data_hash, private_data, presta_data, *locales) unless data_hash.blank? { short_desc: node_value(data_hash, :descriptifCourt, *locales), long_desc: node_value(data_hash, :descriptifDetaille, *locales), theme_desc: data_hash[:descriptifsThematises].blank? ? {} : Hash[data_hash[:descriptifsThematises].map {|th| [node_id(th, :theme), node_value(th, :description, *locales)]}], private_desc: private_data.blank? ? {} : Hash[private_data.map {|d| [d[:nomTechnique], (node_value(d, :descriptif, *locales).blank? ? {LOCALE_FR => d[:libelleFr]} : node_value(d, :descriptif, *locales))]}], accessibility_desc: presta_data.blank? ? {} : Hash[presta_data.select {|k, v| k.to_s.start_with?('descriptifHandicap')}.map {|k, v| [k, node_value(presta_data, k, *locales)]}] } end end |
.parse_entity_fields(information_hash, type_data_hash, sp_hash) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'app/models/apidae/apidae_data_parser.rb', line 355 def self.parse_entity_fields(information_hash, type_data_hash, sp_hash) entity_hash = {} if information_hash if information_hash[:structureGestion] entity_hash.merge!({entity_id: information_hash[:structureGestion][:id], entity_name: information_hash[:structureGestion].dig(:nom, :libelleFr), info_entity_id: (information_hash[:structureInformation] || information_hash[:structureGestion])[:id], info_entity_name: (information_hash[:structureInformation] || information_hash[:structureGestion]).dig(:nom, :libelleFr), service_provider_id: node_id(type_data_hash, :prestataireActivites)}) end if information_hash[:informationsLegales] entity_hash[:legal] = (entity_hash[:legal] || {}).symbolize_keys entity_hash[:legal].merge!(information_hash[:informationsLegales]) end end if sp_hash && sp_hash[:prestataireActivites] entity_hash[:is_service_provider] = true entity_hash[:service_provider_certifications] = lists_ids(sp_hash[:habilitationsPrestataires]) end entity_hash end |
.parse_location_data(location_hash, type_data_hash, territories) ⇒ Object
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 |
# File 'app/models/apidae/apidae_data_parser.rb', line 204 def self.parse_location_data(location_hash, type_data_hash, territories) loc_data = {} unless location_hash.blank? address_hash = location_hash[:adresse] || {} computed_address = [] unless address_hash.blank? computed_address << address_hash[:adresse1] computed_address << address_hash[:adresse2] computed_address << address_hash[:adresse3] end loc_data.merge!({address: computed_address}) loc_data.merge!({place: (type_data_hash ? type_data_hash[:nomLieu] : nil) || address_hash[:nomDuLieu]}) geoloc_details = location_hash[:geolocalisation] if geoloc_details && geoloc_details[:valide] && geoloc_details[:geoJson] loc_data[:latitude] = geoloc_details[:geoJson][:coordinates][1] loc_data[:longitude] = geoloc_details[:geoJson][:coordinates][0] end loc_data[:map_reference] = geoloc_details[:reperePlan] loc_data[:valid] = geoloc_details[:valide] == true loc_data[:altitude] = geoloc_details[:altitude] if geoloc_details loc_data[:access] = node_value(geoloc_details, :complement) if geoloc_details loc_data[:environments] = location_hash[:environnements].map {|e| e[:id]} if location_hash[:environnements] end loc_data[:territories] = territories.map {|t| t[:id]} unless territories.blank? loc_data end |
.parse_openings(openings_hash, opening_days, *locales) ⇒ Object
Note : use internal format for openings storage (ideally Apihours one, to merge data from both sources)
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'app/models/apidae/apidae_data_parser.rb', line 232 def self.parse_openings(openings_hash, opening_days, *locales) if openings_hash && openings_hash[:periodeEnClair] { openings_desc: node_value(openings_hash, :periodeEnClair, *locales), openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL, openings: build_openings(openings_hash, *locales), all_year_long: openings_hash[:ouvertTouteLAnnee] == 'OUVERT_TOUTE_L_ANNEE' ? 'true' : 'false', time_periods: lists_ids(openings_hash[:indicationsPeriode]), openings_extra: lists_ids(openings_hash[:ouverturesComplementaires]), opening_days: opening_days } end end |
.parse_owner_data(data_hash, polls_data) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/apidae/apidae_data_parser.rb', line 106 def self.parse_owner_data(data_hash, polls_data) owner_data = {} unless data_hash.blank? owner_data.merge!({owner_name: data_hash[:nom], owner_id: data_hash[:id]}) end unless polls_data.blank? owner_data.merge!({polls: polls_data[:enquetes] || []}) end owner_data end |
.parse_pictures_data(pictures_array, *locales) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/models/apidae/apidae_data_parser.rb', line 129 def self.parse_pictures_data(pictures_array, *locales) pics_data = {} unless pictures_array.blank? l = locales.blank? ? [DEFAULT_LOCALE] : locales l.each do |locale| pics_data[locale] = [] pictures_array.select { |p| p.is_a?(Hash) && !p[:traductionFichiers].blank? }.each do |pic| pic_file = pic[:traductionFichiers][0] pics_data[locale] << { id: pic[:identifiant], name: localized_value(pic, :nom, locale), url: pic_file[:url].gsub('http:', 'https:'), description: localized_value(pic, :legende, locale), credits: localized_value(pic, :copyright, locale), expiration_date: pic[:dateLimiteDePublication] || '', remote_file_name: pic_file[:fileName] || '', properties: {size: pic_file[:taille], width: pic_file[:largeur], height: pic_file[:hauteur]} } end end end {pictures: pics_data} end |
.parse_rates(rates_hash, *locales) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'app/models/apidae/apidae_data_parser.rb', line 246 def self.parse_rates(rates_hash, *locales) if rates_hash desc = rates_hash[:gratuit] ? {DEFAULT_LOCALE => 'gratuit'} : node_value(rates_hash, :tarifsEnClair, *locales) values = rates_hash[:periodes].blank? ? [] : rates_hash[:periodes].map {|p| build_rate(p, *locales)} methods = rates_hash[:modesPaiement].blank? ? [] : rates_hash[:modesPaiement].map {|p| p[:id]} { rates_desc: desc, rates: values, rates_category: rates_hash[:indicationTarif], payment_methods: methods, tax_included: (rates_hash[:taxeDeSejourIncluse].blank? || rates_hash[:taxeDeSejourIncluse] == 'NON_COMMUNIQUE') ? nil : (rates_hash[:taxeDeSejourIncluse] == 'OUI'), rates_desc_mode: rates_hash[:tarifsEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL, includes: node_value(rates_hash, :leTarifComprend, *locales), excludes: node_value(rates_hash, :leTarifNeComprendPas, *locales), rates_extra: node_value(rates_hash, :complement, *locales) } end end |
.parse_service_data(data_hash, type_data_hash) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'app/models/apidae/apidae_data_parser.rb', line 300 def self.parse_service_data(data_hash, type_data_hash) if data_hash { services: lists_ids(data_hash[:services]), equipments: lists_ids(data_hash[:equipements]), comfort: lists_ids(data_hash[:conforts]), activities: lists_ids(data_hash[:activites], type_data_hash ? type_data_hash[:activites] : [], type_data_hash ? type_data_hash[:activitesSportives] : [], type_data_hash ? type_data_hash[:activitesCulturelles] : []), challenged: lists_ids(data_hash[:tourismesAdaptes]), languages: lists_ids(data_hash[:languesParlees]), documentation_languages: lists_ids(data_hash[:languesDocumentation]) } end end |
.parse_tags_data(pres_data_hash, crit_data_hash, linked_data_hash) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'app/models/apidae/apidae_data_parser.rb', line 316 def self.(pres_data_hash, crit_data_hash, linked_data_hash) = {} if pres_data_hash [:promo] = lists_ids(pres_data_hash[:typologiesPromoSitra]) end unless crit_data_hash.blank? [:internal] = crit_data_hash.map {|c| c[:id]} end unless linked_data_hash.blank? || linked_data_hash[:liensObjetsTouristiquesTypes].blank? [:linked] = linked_data_hash[:liensObjetsTouristiquesTypes] .map {|l| {apidae_id: l[:objetTouristique][:id], apidae_type: l[:objetTouristique][:type], category: l[:type]}} end end |
.parse_title(data_hash, *locales) ⇒ Object
102 103 104 |
# File 'app/models/apidae/apidae_data_parser.rb', line 102 def self.parse_title(data_hash, *locales) {title: node_value(data_hash, :nom, *locales)} end |
.parse_town(location_hash) ⇒ Object
346 347 348 349 350 351 352 353 |
# File 'app/models/apidae/apidae_data_parser.rb', line 346 def self.parse_town(location_hash) if location_hash address_hash = location_hash[:adresse] (!address_hash.blank? && address_hash[:commune]) ? Town.find_by_apidae_id(address_hash[:commune][:id]) : nil else nil end end |
.parse_type_data(apidae_obj, type_hash, presta_hash, business_hash, ratings_list, *locales) ⇒ Object
262 263 264 265 266 267 268 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 297 298 |
# File 'app/models/apidae/apidae_data_parser.rb', line 262 def self.parse_type_data(apidae_obj, type_hash, presta_hash, business_hash, , *locales) data_hash = type_hash || {} prestations_hash = presta_hash || {} apidae_obj.apidae_subtype = lists_ids(data_hash[:typesManifestation]).first if apidae_obj.apidae_type == Obj::FEM apidae_obj.apidae_subtype = node_id(data_hash, :rubrique) if apidae_obj.apidae_type == Obj::EQU apidae_obj.apidae_subtype = lists_ids(data_hash[:typesHebergement]).first if apidae_obj.apidae_type == Obj::SPA { categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories], data_hash[:typesHabitation]), themes: lists_ids(data_hash[:themes]), capacity: (data_hash[:capacite] || {}) .merge(presta_hash ? {group_min: (presta_hash[:nombrePersonnesMinimum] || presta_hash[:tailleGroupeMin]), group_max: presta_hash[:tailleGroupeMax], age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax], wheelchair_max: presta_hash[:nombrePersonnesEnFauteuilRoulantAccueilliesSimultanement]} : {}), classification: nodes_ids(data_hash[:classement], data_hash[:classementPrefectoral], data_hash[:classification]) + lists_ids(data_hash[:classementsGuides]) + lists_ids(data_hash[:classements]), classification_date: data_hash[:dateClassement], classification_ref: data_hash[:numeroClassement], labels: lists_ids(data_hash[:labels], data_hash[:labelsChartesQualite], prestations_hash[:labelsTourismeHandicap]) + (node_id(data_hash, :typeLabel) ? [node_id(data_hash, :typeLabel)] : []), chains: lists_ids(data_hash[:chaines]) + nodes_ids(data_hash[:chaineEtLabel]), ratings: ( || []).map {|r| {id: r[:id], type: r.dig(:nom, :id), rating: r.dig(:qualification, :id), ref: r[:numero], start_date: r[:dateDebutValidite], end_date: r[:dateFinValidite], last_visit: r[:dateDerniereVisite]}}, area: apidae_obj.apidae_type == Obj::DOS ? data_hash.except(:classification) : node_value(data_hash, :lieuDePratique), track: apidae_obj.apidae_type == Obj::EQU ? (data_hash[:itineraire] || {}).except(:passagesDelicats) : nil, tricky_sections: apidae_obj.apidae_type == Obj::EQU ? node_value(data_hash[:itineraire], :passagesDelicats, *locales) : nil, products: lists_ids(data_hash[:typesProduit], data_hash[:aopAocIgps], data_hash[:specialites]), audience: lists_ids(prestations_hash[:typesClientele]), animals: {allowed: prestations_hash[:animauxAcceptes] == 'ACCEPTES', unknown: prestations_hash[:animauxAcceptes] == 'NON_DISPONIBLE', desc: node_value(prestations_hash, :descriptifAnimauxAcceptes, *locales), fee: prestations_hash[:animauxAcceptesSupplement] == 'AVEC_SUPPLEMENT'}, extra: apidae_obj.apidae_type == Obj::SPA ? node_value(data_hash, :formuleHebergement, *locales) : node_value(prestations_hash, :complementAccueil, *locales), duration: apidae_obj.apidae_type == Obj::SPA ? {days: data_hash[:nombreJours], nights: data_hash[:nombreNuits]} : data_hash[:dureeSeance], certifications: data_hash[:agrements].blank? ? {} : Hash[data_hash[:agrements].map {|a| [a[:type][:id].to_s, a[:numero]]}], business: (business_hash || {}).except(:sallesEquipeesPour, :sallesEquipement, :sallesRestauration, :sallesReunion, :sallesHebergement), business_equipments: lists_ids((business_hash || {})[:sallesEquipeesPour], (business_hash || {})[:sallesEquipement], (business_hash || {})[:sallesRestauration], (business_hash || {})[:sallesHebergement]), business_rooms: (business_hash || {})[:sallesReunion] } end |
.parse_versioned_fields(data_hash) ⇒ Object
55 56 57 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/apidae/apidae_data_parser.rb', line 55 def self.parse_versioned_fields(data_hash) version_fields = data_hash[:champsAspect] || [] matched_fields = [] version_fields.each do |f| case f when 'nom' matched_fields << 'title' when 'presentation.descriptifCourt' matched_fields << 'short_desc' when 'presentation.descriptifDetaille' matched_fields << 'long_desc' when 'illustrations' matched_fields << 'pictures' when 'multimedias' matched_fields << 'attachments' when 'informations.moyensCommunication' matched_fields << 'contact' when 'descriptifsThematises' matched_fields << 'theme_desc' when 'ouverture.periodesOuvertures', 'ouverture.periodeEnClair' matched_fields << 'openings_desc' matched_fields << 'openings' when 'ouverture.periodeEnClairAutomatique' matched_fields << 'openings_desc_mode' when 'descriptionTarif.tarifsEnClair', 'descriptionTarif.periodes' matched_fields << 'rates_desc' matched_fields << 'rates' when 'descriptionTarif.tarifsEnClairAutomatique' matched_fields << 'rates_desc_mode' when 'prestations.equipements' matched_fields << 'equipments' when 'prestations.activites' matched_fields << 'activities' when 'prestations.services' matched_fields << 'services' when 'localisation.environnements' matched_fields << 'environments' when 'prestations.complementAccueil' matched_fields << 'extra' when 'localisation.geolocalisation.complement' matched_fields << 'access' else end end matched_fields.uniq end |