app/models/apidae/apidae_data_parser.rb in apidae-1.2.35 vs app/models/apidae/apidae_data_parser.rb in apidae-1.3.0

- old
+ new

@@ -42,11 +42,11 @@ WEEKDAYS_MAP = { 'LUNDI' => MONDAY, 'MARDI' => TUESDAY, 'MERCREDI' => WEDNESDAY, - 'JEUDI' => THURSDAY, + 'JEUD' => THURSDAY, 'VENDREDI' => FRIDAY, 'SAMEDI' => SATURDAY, 'DIMANCHE' => SUNDAY } @@ -99,29 +99,23 @@ def self.parse_title(data_hash, *locales) {title: node_value(data_hash, :nom, *locales)} end - def self.parse_owner_data(data_hash, polls_data) - owner_data = {} + def self.parse_owner_data(data_hash) unless data_hash.blank? - owner_data.merge!({owner_name: data_hash[:nom], owner_id: data_hash[:id]}) + {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 - def self.parse_desc_data(data_hash, private_data, presta_data, *locales) + def self.parse_desc_data(data_hash, private_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)]}] + private_desc: private_data.blank? ? {} : Hash[private_data.map {|d| [d[:nomTechnique], node_value(d, :descriptif, *locales)]}] } end end def self.parse_pictures_data(pictures_array, *locales) @@ -155,11 +149,10 @@ 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 @@ -213,26 +206,24 @@ end def self.parse_location_data(location_hash, type_data_hash, territories) loc_data = {} unless location_hash.blank? - address_hash = location_hash[:adresse] || {} + 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] + computed_address << address_hash[:adresse1] unless address_hash[:adresse1].blank? + computed_address << address_hash[:adresse2] unless address_hash[:adresse2].blank? + computed_address << address_hash[:adresse3] unless address_hash[:adresse3].blank? end loc_data.merge!({address: computed_address}) - loc_data.merge!({place: (type_data_hash ? type_data_hash[:nomLieu] : nil) || address_hash[:nomDuLieu]}) + loc_data.merge!({place: type_data_hash[:nomLieu]}) if type_data_hash 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[: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 @@ -243,11 +234,10 @@ 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]) } end end @@ -255,14 +245,12 @@ 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, payment_methods: methods, - tax_included: rates_hash[:taxeDeSejourIncluse].blank? ? 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) } @@ -274,37 +262,30 @@ 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]), + categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories]), themes: lists_ids(data_hash[:themes]), capacity: (data_hash[:capacite] || {}) .merge(presta_hash ? {group_min: presta_hash[:tailleGroupeMin], group_max: presta_hash[:tailleGroupeMax], - age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax], - wheelchair_max: presta_hash[:nombrePersonnesEnFauteuilRoulantAccueilliesSimultanement]} : {}), + age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax]} : {}), 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]), 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, + track: apidae_obj.apidae_type == Obj::EQU ? data_hash[:itineraire] : 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', 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? ? [] : data_hash[:agrements].map {|a| {id: a[:type][:id], identifier: 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] + business: business_hash } end def self.parse_service_data(data_hash, type_data_hash) if data_hash @@ -314,12 +295,11 @@ 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]) + languages: lists_ids(data_hash[:languesParlees]) } end end def self.parse_tags_data(pres_data_hash, crit_data_hash, linked_data_hash) @@ -335,23 +315,17 @@ .map {|l| {apidae_id: l[:objetTouristique][:id], apidae_type: l[:objetTouristique][:type], category: l[:type]}} end tags end - def self.parse_booking(reservation_hash, visits_hash, *locales) - booking_hash = {} + def self.parse_booking(reservation_hash, *locales) if reservation_hash - booking_hash[:booking_desc] = node_value(reservation_hash, :complement, *locales) - booking_hash[:booking_entities] = reservation_hash[:organismes] + { + booking_desc: node_value(reservation_hash, :complement, *locales), + 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 def self.parse_town(location_hash) if location_hash address_hash = location_hash[:adresse] @@ -359,27 +333,13 @@ else nil end end - 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.merge!({legal: information_hash[:informationsLegales]}) - end + def self.parse_entity_fields(information_hash, type_data_hash) + if information_hash && information_hash[:structureGestion] + {entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)} end - if sp_hash && sp_hash[:prestataireActivites] - entity_hash[:is_service_provider] = true - end - entity_hash end def self.node_id(node, key) node[key][:id] if node && node[key] end \ No newline at end of file