sitra_client 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bf7717dd12ece88029946b5ce751736f15e0e9c
4
- data.tar.gz: 0b1fd13c206a166295a9e5a0111a42de0250ee6e
3
+ metadata.gz: 03c0e5f7c528194aee12c4e7192d07536ee42487
4
+ data.tar.gz: 8ffbbac92e296e88230ead9b57823137d503d9c7
5
5
  SHA512:
6
- metadata.gz: 91baf5ec3a14abb51961f9d0bde7877a4ab4077546f0fd4271d3529caa5a8c15db22fc1618ec11a6076fd35e00de747070e1d82b1667c022fa54a17f21751c1c
7
- data.tar.gz: af9ec62d87f46c00c4a12cbd6a696d706d0b5bccbc69b4154745cad949e1a43ef32bb28491c8fbf3ef380038e0d049ca29db2de7d40336d8defae77329d61fc8
6
+ metadata.gz: fff07c50e9efd03d0fc3bb00170aa6c0a06fdb011b930767baf706b9fc7670d8574129e3b5ebc148da76c16b5ff21b37f995f2ddca2ccd0d90a37acf8f587900
7
+ data.tar.gz: fa41884e542281aa3bdff031fc7cc8e4f80b52e4e95146b0b7a86a893473f907af0d37fac39c5557659d8c68da9d265c00fdeafad2610787acaaedb17e916150
@@ -10,25 +10,6 @@ class TouristicObject
10
10
 
11
11
  include AttributeHelper
12
12
 
13
- SPECIFIC_INFOS = {
14
- 'ACTIVITE' => '@informationsActivite',
15
- 'COMMERCE_ET_SERVICE' => '@informationsCommerceEtService',
16
- 'DEGUSTATION' => '@informationsDegustation',
17
- 'DOMAINE_SKIABLE' => '@informationsDomaineSkiable',
18
- 'EQUIPEMENT' => '@informationsEquipement',
19
- 'FETE_ET_MANIFESTATION' => '@informationsFeteEtManifestation',
20
- 'HEBERGEMENT_COLLECTIF' => '@informationsHebergementCollectif',
21
- 'HEBERGEMENT_LOCATIF' => '@informationsHebergementLocatif',
22
- 'HOTELLERIE' => '@informationsHotellerie',
23
- 'HOTELLERIE_PLEIN_AIR' => '@informationsHotelleriePleinAir',
24
- 'PATRIMOINE_CULTUREL' => '@informationsPatrimoineCulturel',
25
- 'PATRIMOINE_NATUREL' => '@informationsPatrimoineNaturel',
26
- 'RESTAURATION' => '@informationsRestauration',
27
- 'SEJOUR_PACKAGE' => '@informationsSejourPackage',
28
- 'STRUCTURE' => '@informationsStructure',
29
- 'TERRITOIRE' => '@informationsTerritoire'
30
- }
31
-
32
13
  DEFAULT_LIBELLE = :libelleFr
33
14
 
34
15
  ASPECT_WINTER = 'HIVER'
@@ -82,6 +63,32 @@ class TouristicObject
82
63
  @type
83
64
  end
84
65
 
66
+ def specific_info(capitalize = false)
67
+ type = @type.downcase.split('_')
68
+
69
+ if capitalize
70
+ type[0] = type[0].capitalize
71
+ end
72
+
73
+ type.each_index do |index|
74
+ if index > 0
75
+ type[index] = type[index].capitalize
76
+ end
77
+ end
78
+
79
+ @specific_info = type.join('')
80
+ end
81
+
82
+ def sub_type
83
+ infos_label = '@informations' + specific_info(true)
84
+ type_label = specific_info + 'Type'
85
+
86
+ infos_type = instance_variable_get(infos_label)
87
+ if infos_type && infos_type[type_label.to_sym]
88
+ infos_type[type_label.to_sym][@libelle] || infos_type[type_label.to_sym][DEFAULT_LIBELLE]
89
+ end
90
+ end
91
+
85
92
  def title
86
93
  @nom[@libelle] || @nom[DEFAULT_LIBELLE]
87
94
  end
@@ -113,7 +120,7 @@ class TouristicObject
113
120
  def information
114
121
  specific_information = {}
115
122
  unless @type.nil?
116
- specific_information = instance_variable_get(SPECIFIC_INFOS[@type])
123
+ specific_information = instance_variable_get('@informations' + specific_info(true))
117
124
  end
118
125
  @informations.merge(specific_information)
119
126
  end
@@ -295,6 +302,14 @@ class TouristicObject
295
302
  is_eligible
296
303
  end
297
304
 
305
+ def certification
306
+ info_specific = instance_variable_get('@informations' + specific_info(true))
307
+
308
+ if info_specific && info_specific[:labels]
309
+ info_specific[:labels].collect {|t| t[:id]}
310
+ end
311
+ end
312
+
298
313
  private
299
314
 
300
315
  def occurrence_in_month(date)
@@ -1,3 +1,3 @@
1
1
  module SitraClient
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
@@ -24,7 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "shoulda"
25
25
  spec.add_runtime_dependency "rails", ">= 4.0"
26
26
  spec.add_runtime_dependency "json"
27
- if RUBY_VERSION < '2.3'
28
- spec.add_runtime_dependency "backport_dig"
29
- end
27
+ spec.add_runtime_dependency "ruby_dig"
30
28
  end
@@ -330,52 +330,69 @@ class TouristicObjectTest < Test::Unit::TestCase
330
330
  assert_equal false, touristic_object.open_on?('2015-2-3', '2015-2-10')
331
331
  end
332
332
 
333
- should 'load overridden aspect values' do
334
- hash = {
335
- nom: {libelleFr: 'my_title'},
336
- presentation: {
337
- descriptifCourt: {libelleFr: 'my_description'},
338
- descriptifDetaille: {libelleFr: 'my_detailed_description'}
339
- },
340
- ouverture: {
341
- periodeEnClair: {libelleFr: 'my_opening_hours'},
342
- periodesOuvertures: [
343
- {dateDebut: '2014-1-1', dateFin: '2014-12-31', tousLesAns: true, type: 'OUVERTURE_MOIS'},
344
- {dateDebut: '2015-1-1', dateFin: '2015-1-31', tousLesAns: false, type: 'OUVERTURE_SEMAINE'}
345
- ]
346
- },
347
- aspects: [
348
- {
349
- aspect: 'HIVER',
350
- champsAspect: ['presentation.descriptifCourt', 'presentation.descriptifDetaille', 'ouverture.periodesOuvertures'],
351
- presentation: {
352
- descriptifCourt: {libelleFr: 'my_description hiver'}
353
- },
354
- ouverture: {
355
- periodesOuvertures: [
356
- {dateDebut: '2014-2-1', dateFin: '2014-4-30', tousLesAns: true, type: 'OUVERTURE_MOIS'}
357
- ]
358
- },
333
+ should 'populate cetification information for provided fields' do
334
+ hash_results = { type: "HEBERGEMENT_COLLECTIF",
335
+ informationsHebergementCollectif: {
336
+ labels: [{id: '1256'},
337
+ {id: '5478'},
338
+ {id: '7899'}]
339
+ }
340
+ }
341
+
342
+ touristic_object = TouristicObject.new(hash_results)
343
+
344
+ assert_equal('1256', touristic_object.certification[0])
345
+ assert_equal('5478', touristic_object.certification[1])
346
+ assert_equal('7899', touristic_object.certification[2])
347
+ assert_not_equal('5555', touristic_object.certification[2])
348
+ end
349
+
350
+ should 'not populate certification information if empty' do
351
+ hash_results = { type: 'HEBERGEMENT_LOCATIF',
352
+ informationsHebergementLocatif: {
353
+ labels: []
354
+ }
355
+ }
356
+
357
+ touristic_object = TouristicObject.new(hash_results)
358
+
359
+ assert_equal([], touristic_object.certification)
360
+ end
361
+
362
+ should 'return specific info of the touristic object' do
363
+ array_types = ['ACTIVITE', 'COMMERCE_ET_SERVICE', 'DEGUSTATION', 'DOMAINE_SKIABLE', 'EQUIPEMENT', 'FETE_ET_MANIFESTATION',
364
+ 'HEBERGEMENT_COLLECTIF', 'HEBERGEMENT_LOCATIF', 'HOTELLERIE', 'HOTELLERIE_PLEIN_AIR',
365
+ 'PATRIMOINE_CULTUREL', 'PATRIMOINE_NATUREL', 'RESTAURATION', 'SEJOUR_PACKAGE', 'STRUCTURE', 'TERRITOIRE']
366
+
367
+ expected = ['activite', 'commerceEtService', 'degustation', 'domaineSkiable', 'equipement', 'feteEtManifestation', 'hebergementCollectif',
368
+ 'hebergementLocatif', 'hotellerie', 'hotelleriePleinAir', 'patrimoineCulturel', 'patrimoineNaturel', 'restauration',
369
+ 'sejourPackage', 'structure', 'territoire']
370
+
371
+ results = []
372
+
373
+ array_types.each do |type|
374
+ hash_results = { type: type }
375
+ touristic_type = TouristicObject.new(hash_results)
376
+ results << touristic_type.specific_info
377
+ end
378
+
379
+ assert_equal expected, results
380
+ end
381
+
382
+ should 'populate sub type label for provided fields' do
383
+ hash_results = {
384
+ type: 'HOTELLERIE_PLEIN_AIR',
385
+ informationsHotelleriePleinAir: {
386
+ hotelleriePleinAirType: {
387
+ libelleFr: 'label'
359
388
  }
360
- ]
389
+ }
361
390
  }
362
391
 
363
- std_object = TouristicObject.new(hash)
364
- winter_object = TouristicObject.new(hash.deep_dup, TouristicObject::ASPECT_WINTER)
365
-
366
- assert_equal 'my_title', std_object.title
367
- assert_equal 'my_description', std_object.description
368
- assert_equal 'my_detailed_description', std_object.details
369
- assert_equal 'my_opening_hours', std_object.horaires
370
- assert_equal [{dateDebut: '2014-1-1', dateFin: '2014-12-31', tousLesAns: true, type: 'OUVERTURE_MOIS'},
371
- {dateDebut: '2015-1-1', dateFin: '2015-1-31', tousLesAns: false, type: 'OUVERTURE_SEMAINE'}],
372
- std_object.attributes['ouverture'][:periodesOuvertures]
373
-
374
- assert_equal 'my_title', winter_object.title
375
- assert_equal 'my_description hiver', winter_object.description
376
- assert_nil winter_object.details
377
- assert_equal 'my_opening_hours', winter_object.horaires
378
- assert_equal [{dateDebut: '2014-2-1', dateFin: '2014-4-30', tousLesAns: true, type: 'OUVERTURE_MOIS'}],
379
- winter_object.attributes['ouverture'][:periodesOuvertures]
392
+ touristic_object = TouristicObject.new(hash_results)
393
+
394
+ assert_equal('label', touristic_object.sub_type)
380
395
  end
396
+
397
+
381
398
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitra_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeanbaptistevilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby_dig
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Sitra Client Gem
98
112
  email:
99
113
  - jbvilain@gmail.com