flights_gui_tests 0.0.1

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.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/features/data/host.yml +78 -0
  4. data/features/data/miles.yml +216 -0
  5. data/features/data/sites.yml +44 -0
  6. data/features/data/tag_microsoft.yml +68 -0
  7. data/features/step_definitions/checkout/checkout_steps.rb +24 -0
  8. data/features/step_definitions/checkout/form_steps.rb +20 -0
  9. data/features/step_definitions/checkout/load_steps.rb +36 -0
  10. data/features/step_definitions/conditional_steps.rb +12 -0
  11. data/features/step_definitions/cookies_steps.rb +8 -0
  12. data/features/step_definitions/flights_tracker/flights_tracker_steps.rb +30 -0
  13. data/features/step_definitions/landing/itineraries_steps.rb +75 -0
  14. data/features/step_definitions/landing/landing_steps.rb +59 -0
  15. data/features/step_definitions/landing/load_steps.rb +30 -0
  16. data/features/step_definitions/page_steps.rb +18 -0
  17. data/features/step_definitions/results/basefare_steps.rb +65 -0
  18. data/features/step_definitions/results/desambiguation_steps.rb +144 -0
  19. data/features/step_definitions/results/errors_steps.rb +23 -0
  20. data/features/step_definitions/results/filters_steps.rb +301 -0
  21. data/features/step_definitions/results/load_steps.rb +52 -0
  22. data/features/step_definitions/results/matrix_steps.rb +213 -0
  23. data/features/step_definitions/results/order_steps.rb +49 -0
  24. data/features/step_definitions/results/pagination_steps.rb +29 -0
  25. data/features/step_definitions/results/recommendation_steps.rb +75 -0
  26. data/features/step_definitions/results/results_steps.rb +40 -0
  27. data/features/step_definitions/results/reviews_steps.rb +16 -0
  28. data/features/step_definitions/results/tags_steps.rb +102 -0
  29. data/features/step_definitions/results/wish_list_steps.rb +114 -0
  30. data/features/step_definitions/thanks/load_steps.rb +10 -0
  31. data/features/step_definitions/thanks/thanks_steps.rb +12 -0
  32. data/features/support/classes/clusters/checkout_cluster.rb +117 -0
  33. data/features/support/classes/clusters/data/data.rb +33 -0
  34. data/features/support/classes/clusters/results/details_cluster.rb +36 -0
  35. data/features/support/classes/clusters/results/landing_cluster.rb +29 -0
  36. data/features/support/classes/clusters/results/render_cluster.rb +83 -0
  37. data/features/support/classes/clusters/results_cluster.rb +171 -0
  38. data/features/support/classes/date.rb +26 -0
  39. data/features/support/classes/element.rb +23 -0
  40. data/features/support/classes/price.rb +66 -0
  41. data/features/support/classes/process_manager.rb +104 -0
  42. data/features/support/classes/string.rb +16 -0
  43. data/features/support/env.rb +94 -0
  44. data/features/support/hooks.rb +20 -0
  45. data/features/support/matchers.rb +108 -0
  46. data/features/support/modules/accessor.rb +26 -0
  47. data/features/support/modules/browser.rb +80 -0
  48. data/features/support/modules/checkout/datos_de_facturacion.rb +64 -0
  49. data/features/support/modules/checkout/informacion_de_contacto.rb +30 -0
  50. data/features/support/modules/checkout/pasajeros.rb +71 -0
  51. data/features/support/modules/checkout/tarjeta.rb +71 -0
  52. data/features/support/modules/element.rb +12 -0
  53. data/features/support/modules/helpers.rb +64 -0
  54. data/features/support/modules/pages/cookies.rb +33 -0
  55. data/features/support/modules/pages/tags.rb +27 -0
  56. data/features/support/modules/results/filters.rb +37 -0
  57. data/features/support/modules/results/itineraries/bussines.rb +17 -0
  58. data/features/support/modules/results/itineraries/data.rb +25 -0
  59. data/features/support/modules/results/itineraries/details.rb +80 -0
  60. data/features/support/modules/results/itineraries/miles.rb +64 -0
  61. data/features/support/modules/results/itineraries/payments.rb +27 -0
  62. data/features/support/modules/results/matrix/matrix_airline.rb +52 -0
  63. data/features/support/modules/results/matrix/matrix_fare_chart.rb +21 -0
  64. data/features/support/modules/results/matrix/matrix_price.rb +18 -0
  65. data/features/support/modules/results/recommendation.rb +29 -0
  66. data/features/support/modules/results/search_params.rb +21 -0
  67. data/features/support/modules/results/wish_list.rb +33 -0
  68. data/features/support/pages/all_pages.rb +95 -0
  69. data/features/support/pages/checkout/checkout_page.rb +45 -0
  70. data/features/support/pages/checkout/popup_results_page.rb +39 -0
  71. data/features/support/pages/flights_tracker/search_page.rb +54 -0
  72. data/features/support/pages/landing/search_page.rb +94 -0
  73. data/features/support/pages/results/desambiguation_airports_page.rb +16 -0
  74. data/features/support/pages/results/desambiguation_city_page.rb +20 -0
  75. data/features/support/pages/results/search_page.rb +101 -0
  76. data/features/support/pages/thanks/thanks_page.rb +7 -0
  77. data/features/tests/checkout/book_ok.feature +209 -0
  78. data/features/tests/flights_tracker/search.feature +65 -0
  79. data/features/tests/landing/search.feature +152 -0
  80. data/features/tests/results/basefare.feature +90 -0
  81. data/features/tests/results/desambiguation/airports.feature +89 -0
  82. data/features/tests/results/desambiguation/city.feature +87 -0
  83. data/features/tests/results/errors.feature +198 -0
  84. data/features/tests/results/filters.feature +113 -0
  85. data/features/tests/results/itineraries.feature +93 -0
  86. data/features/tests/results/matrix/matrix_airlines.feature +46 -0
  87. data/features/tests/results/matrix/matrix_fare_chart.feature +41 -0
  88. data/features/tests/results/matrix/matrix_price.feature +41 -0
  89. data/features/tests/results/orders.feature +89 -0
  90. data/features/tests/results/pagination.feature +74 -0
  91. data/features/tests/results/recommendation.feature +111 -0
  92. data/features/tests/results/reviews_airlines.feature +84 -0
  93. data/features/tests/results/search.feature +209 -0
  94. data/features/tests/results/wish_list.feature +55 -0
  95. data/flights_gui_tests.gemspec +34 -0
  96. data/henry-context.yml +4938 -0
  97. metadata +306 -0
@@ -0,0 +1,117 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Checkout
3
+ class CheckoutCluster
4
+
5
+ attr_accessor :ida, :vuelta, :tarifas, :idas, :vueltas
6
+
7
+ def initialize(itinerario,html,page = 0)
8
+ self.load_prices((html/"div.price-info"))
9
+ eval "#{itinerario.downcase}(html)"
10
+ end
11
+ def roundtrip(html)
12
+ self.load_data_from((html/"div#itinerary div[@class='route outbound-route row-col']"))
13
+ self.load_data_to((html/"div#itinerary div[@class='route inbound-route row-col']"))
14
+ end
15
+ def oneway(html)
16
+ self.load_data_from((html/"div#itinerary div[@class='route outbound-route row-col']"))
17
+ @nro_vuelo_vuelta = -1
18
+ end
19
+ def multipledestinations(html)
20
+ self.load_data_from((html/"div#itinerary div[@class='route outbound-route row-col']"))
21
+ self.load_data_to((html/"div#itinerary div[@class='route outbound-route row-col']").last)
22
+ end
23
+ def load_data_from(div_datos)
24
+ @idas = Array.new
25
+ (div_datos/"div.segment").each do |div_datos_ida|
26
+ origen = (div_datos/"span.cities").first.inner_html.to_s.match("(.*)\<span class=\"separator\"\>\<\/span\>(.*)")[1].strip.no_accents
27
+ destino= (div_datos/"span.cities").last.inner_html.to_s.match("(.*)\<span class=\"separator\"\>\<\/span\>(.*)")[2].strip.no_accents
28
+ origen_iata = (div_datos/"li.outbound a")[0].inner_text.strip
29
+ destino_iata = (div_datos/"li.inbound a")[-1].inner_text.strip
30
+ fecha = (div_datos_ida/"li.outbound span.date")[0] ? (div_datos_ida/"li.outbound span.date")[0].inner_text.strip.no_accents : (div_datos_ida/"li.inbound span.date")[0].inner_text.strip.no_accents
31
+ escala = (div_datos/"span.stops a").inner_text.strip.empty? ? "Sin escalas" : (div_datos/"span.stops a").inner_text.to_i
32
+ aerolinea = Array.new
33
+ i = 0
34
+ (div_datos_ida/"span.airline-logo//img").each do |aer|
35
+ aerolinea << aer.attributes['src'].match(/(..).png/)[1].upcase
36
+ i = i + 1
37
+ end
38
+ hou_sal_ida = Time.parse((div_datos/"li.outbound").first.inner_html.to_s.match("(.*)\<\/span\>(.*)hs(.*)\<a(.*)")[2].strip.no_accents)
39
+ hou_lle_ida = Time.parse((div_datos/"li.outbound").last.inner_html.to_s.match("(.*)\<\/span\>(.*)hs(.*)\<a(.*)")[2].strip.no_accents)
40
+ @idas << DataCluster.new(origen,destino,fecha, aerolinea, escala_to_i(escala),origen_iata,destino_iata,hou_sal_ida,hou_lle_ida)
41
+ end
42
+ @nro_vuelo_ida = 0
43
+ @ida = @idas[@nro_vuelo_ida]
44
+
45
+ end
46
+ def load_data_to(div_datos)
47
+ @vueltas = Array.new
48
+ (div_datos/"div.segment").each do |div_datos_vuelta|
49
+ origen = (div_datos/"span.cities").first.inner_html.to_s.match("(.*)\<span class=\"separator\"\>\<\/span\>(.*)")[1].strip.no_accents
50
+ destino= (div_datos/"span.cities").last.inner_html.to_s.match("(.*)\<span class=\"separator\"\>\<\/span\>(.*)")[2].strip.no_accents
51
+ origen_iata = (div_datos/"li.outbound a")[0].inner_text.strip
52
+ destino_iata = (div_datos/"li.inbound a")[-1].inner_text.strip
53
+ fecha = (div_datos_vuelta/"li.outbound span.date")[0] ? (div_datos_vuelta/"li.outbound span.date")[0].inner_text.strip.no_accents : (div_datos_vuelta/"li.inbound span.date")[0].inner_text.strip.no_accents
54
+ escala = (div_datos/"span.stops a").inner_text.strip.empty? ? "Sin escalas" : (div_datos/"span.stops a").inner_text.to_i
55
+ aerolinea = Array.new
56
+ i = 0
57
+ (div_datos_vuelta/"span.airline-logo//img").each do |aer|
58
+ aerolinea << aer.attributes['src'].match(/(..).png/)[1].upcase
59
+ i = i + 1
60
+ end
61
+ hou_sal_ida = Time.parse((div_datos/"li.outbound").first.inner_html.to_s.match("(.*)\<\/span\>(.*)hs(.*)\<a(.*)")[2].strip.no_accents)
62
+ hou_lle_ida = Time.parse((div_datos/"li.outbound").last.inner_html.to_s.match("(.*)\<\/span\>(.*)hs(.*)\<a(.*)")[2].strip.no_accents)
63
+ @vueltas << DataCluster.new(origen,destino,fecha, aerolinea, escala_to_i(escala),origen_iata,destino_iata,hou_sal_ida,hou_lle_ida)
64
+ end
65
+ @nro_vuelo_vuelta = 0
66
+ @vuelta = @vueltas[@nro_vuelo_vuelta]
67
+
68
+ end
69
+ def load_prices(p_html)
70
+
71
+ @tarifas = Hash.new
72
+ if (p_html/"span#secondary-currency").empty?
73
+ @tarifas['tarifa_adulto'] = Price.new((p_html/"li.adult-price span[@class='price-currency'] span.currency").first.inner_text.strip + " " + (p_html/"li.adult-price span[@class='price-currency'] span.amount").first.inner_text.strip)
74
+ else
75
+ @tarifas['tarifa_adulto'] = Price.new((p_html/"div.adult-price-conversion span#local-currency span.code").first.inner_text.strip + " " + (p_html/"div.adult-price-conversion span#local-currency span.amount").first.inner_text.strip)
76
+ end
77
+
78
+ adt = (p_html/"li.adult_fare").select{|li| li.inner_text.no_accents.downcase =~ /adulto|adult/}.first
79
+ @tarifas['adt'] = adt ? Price.new((adt/"span.currency").first.inner_text.strip + " " + (adt/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
80
+
81
+ cnn = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /nino|criancas|child/}.first
82
+ @tarifas['cnn'] = cnn ? Price.new((cnn/"span.currency").first.inner_text.strip + " " + (cnn/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
83
+
84
+ inf = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /bebe|infant/}.first
85
+ @tarifas['inf'] = inf ? Price.new((inf/"span.currency").first.inner_text.strip + " " + (inf/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
86
+
87
+ tasas = (p_html/"li.taxes").empty? ? (p_html/"li[@class='taxDetail.OTHER-price']").first : (p_html/"li.taxes").first
88
+ @tarifas['tasas'] = tasas ? Price.new((tasas/"span.currency").first.inner_text.strip + " " + (tasas/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
89
+
90
+ cargos = (p_html/"li.charges").first
91
+ @tarifas['cargos'] = cargos ? Price.new((cargos/"span.currency").first.inner_text.strip + " " + (cargos/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
92
+
93
+ afip = (p_html/"li.tax_afip").first
94
+ @tarifas['afip'] = afip ? Price.new((afip/"span.currency").first.inner_text.strip + " " + (afip/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
95
+
96
+ servicio = (p_html/"li.service_taxes").first
97
+ @tarifas['encargos'] = servicio ? Price.new((servicio/"span.currency").first.inner_text.strip + " " + (servicio/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
98
+
99
+ campo = "total"
100
+ @tarifas['total'] = (p_html/"li.#{campo} span.currency").empty? ? Price.new("$ 0",true) : Price.new((p_html/"li.#{campo} span.currency").first.inner_text.strip + " " + (p_html/"li.#{campo} span.amount").first.inner_text.strip)
101
+ end
102
+
103
+ def validarSumaDesgloce(linea = "total|tarifa_adulto|tarifa_adulto_dolar")
104
+
105
+ sumaTarifas = 0
106
+ @tarifas.each_pair do |key,tarifa|
107
+ if key !~ /#{linea}/
108
+ sumaTarifas += tarifa.valor
109
+ end
110
+ end
111
+
112
+ return sumaTarifas.to_i
113
+
114
+ end
115
+
116
+ end
117
+ end
@@ -0,0 +1,33 @@
1
+ class DataCluster
2
+ attr_accessor :origen, :destino, :fecha, :aerolinea, :escalas, :destino_iata, :origen_iata, :hou_sal_ida, :hou_lle_ida,:attributes, :duracion
3
+
4
+ def initialize (origen,destino,fecha, aerolinea, escalas, origen_iata=nil, destino_iata=nil,hou_sal_ida=nil,hou_lle_ida=nil,duracion=nil)
5
+
6
+ @duracion = duracion
7
+ @origen = origen
8
+ @destino = destino
9
+ @origen_iata = origen_iata
10
+ @destino_iata = destino_iata
11
+ @fecha = fecha.empty? ? nil : Date.parse_new_result(fecha)
12
+ @aerolinea = aerolinea
13
+ @escalas = escalas
14
+ @hou_sal_ida = hou_sal_ida
15
+ @hou_lle_ida = hou_lle_ida
16
+ @attributes = [:origen, :destino, :origen_iata, :destino_iata, :fecha, :aerolinea, :escalas, :hou_sal_ida, :hou_lle_ida, :duracion]
17
+ end
18
+
19
+ def to_s
20
+ return "Escalas: #{@escalas}, Duracion: #{@duracion}, Origen: #{@origen}, Destino: #{@destino}, Iata: #{@origen_iata}-#{@destino_iata}, Fecha: #{@fecha}, Aerolinea: #{@aerolinea}, Hr salida: #{@hou_sal_ida}, Hr llegada: #{@hou_lle_ida}"
21
+ end
22
+
23
+ #se usa en el dinamico para comparar
24
+ def ==(other)
25
+ eq = true
26
+ self.attributes.each do |attrb|
27
+ if other
28
+ eq = false if self.send(attrb) != other.send(attrb)
29
+ end
30
+ end
31
+ eq
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class DetailsCluster
3
+ attr_accessor :tramos, :duracion
4
+ def initialize(p_html)
5
+ @duracion = (p_html/"div.popup-container div.popup-content span.total-duration").inner_text.strip.no_accents
6
+ @tramos = []
7
+ (p_html/"div.popup-container div.popup-content div.detail").each do |div|
8
+ tramo = Hash.new
9
+ if (div/"div.segment span.not-economy-segments").first.nil?
10
+ tramo['bussines'] = nil
11
+ tramo['clase'] = (div/"div.segment span.class").first.inner_text.strip.no_accents
12
+ else
13
+ tramo['bussines'] = true #((div/"div.segment span.not-economy-segments span.not-economy-segments-description").first.inner_text.strip.no_accents == "Business")
14
+ tramo['clase'] = (div/"div.segment span.not-economy-segments span.not-economy-segments-description").first.inner_text.strip.no_accents
15
+ end
16
+ tramo['ciudad_origen'] = (div/"li.departure span.location span.data").first.inner_text.strip.no_accents
17
+ tramo['fecha_origen'] = Date.parse_new_details((div/"li.departure span.date span.day").first.inner_text.strip.no_accents)
18
+ tramo['hora_origen'] = Time.parse((div/"li.departure span.date span.hour").first.inner_text.strip.no_accents)
19
+ tramo['ciudad_destino'] = (div/"li.arrival span.location span.data").last.inner_text.strip.no_accents
20
+ tramo['hora_destino'] = Time.parse((div/"li.arrival span.date span.hour").last.inner_text.strip.no_accents)
21
+ @tramos << tramo
22
+ end
23
+ end
24
+
25
+ def to_s
26
+ text = String.new
27
+ @tramos.each_with_index do |tramo,i|
28
+ text << "[Tramo #{i}: "
29
+ tramo.each_pair do |key,value|
30
+ text << "#{key}:#{value} - "
31
+ end
32
+ text << "]"
33
+ end
34
+ return text
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class LandingCluster < ResultsCluster
3
+
4
+ def load_prices(p_html)
5
+
6
+ @tarifas = Hash.new
7
+ @tarifas['tarifa_adulto'] = Price.new((p_html/"span.price-currency span.currency").first.inner_text.strip + " " + (p_html/"span.price-currency span.amount").first.inner_text.strip)
8
+ @tarifas['tarifa_adulto_dolar'] = Price.new((p_html/"span.price-currency span.currency").last.inner_text.strip + " " + (p_html/"span.price-currency span.amount").last.inner_text.strip)
9
+ @tarifas['adt'] = (p_html/"ul.fare-detail//li").empty? ? Price.new("$ 0",true) : Price.new(((p_html/"ul.fare-detail//li").select{|li| li.inner_text.no_accents.downcase =~ /adulto/}.first/"span[@class='price-currency ARS']").inner_text.strip)
10
+
11
+ adt = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /adulto/}.first
12
+ @tarifas['adt'] = adt ? Price.new((adt/"span.currency").first.inner_text.strip + " " + (adt/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
13
+
14
+ tasas = (p_html/"li.taxes-price").empty? ? (p_html/"li[@class='taxDetail.OTHER-price']").first : (p_html/"li.taxes-price").first
15
+ @tarifas['tasas'] = tasas ? Price.new((tasas/"span.currency").first.inner_text.strip + " " + (tasas/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
16
+
17
+ cargos = (p_html/"li.charges-price").first
18
+ @tarifas['cargos'] = cargos ? Price.new((cargos/"span.currency").first.inner_text.strip + " " + (cargos/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
19
+
20
+ afip = (p_html/"li[@class='taxDetail.ZK-price']").first
21
+ @tarifas['afip'] = afip ? Price.new((afip/"span.currency").first.inner_text.strip + " " + (afip/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
22
+
23
+ @tarifas['encargos'] = Price.new("$ 0",true)
24
+
25
+ campo = (p_html/"li").empty? ? "total" : "fare"
26
+ @tarifas['total'] = (p_html/"li.#{campo}-price span.currency").empty? ? Price.new("$ 0",true) : Price.new((p_html/"li.#{campo}-price span.currency").first.inner_text.strip + " " + (p_html/"li.#{campo}-price span.amount").first.inner_text.strip)
27
+ end
28
+
29
+ end
@@ -0,0 +1,83 @@
1
+ class RenderCluster < ResultsCluster
2
+ def initialize(itinerario,html,page = 0)
3
+ self.load_prices((html/"div.fare-container"))
4
+ eval "#{itinerario.downcase}(html)"
5
+ end
6
+ def load_prices(p_html)
7
+
8
+ @tarifas = Hash.new
9
+
10
+ if !(p_html/"div.fare-difference").empty?
11
+ con_diferencia(p_html)
12
+ else
13
+ sin_diferencia(p_html)
14
+ end
15
+
16
+ end
17
+
18
+ def con_diferencia(p_html)
19
+ @tarifas = Hash.new
20
+ @tarifas['tarifa_adulto_dolar'] = Price.new((p_html/"span.price-currency span.currency").first.inner_text.strip + " " + (p_html/"span.price-currency span.amount").first.inner_text.strip)
21
+ if (p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.currency").first
22
+ @tarifas['tarifa_adulto'] = Price.new((p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.currency").first.inner_text.strip + " " + (p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.amount").first.inner_text.strip)
23
+ else
24
+ @tarifas['tarifa_adulto'] = @tarifas['tarifa_adulto_dolar']
25
+ end
26
+
27
+ adt = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /adulto/}.first
28
+ @tarifas['adt'] = adt ? Price.new((adt/"span.currency").first.inner_text.strip + " " + (adt/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
29
+
30
+ cnn = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /nino/}.first
31
+ @tarifas['cnn'] = cnn ? Price.new((cnn/"span.currency").first.inner_text.strip + " " + (cnn/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
32
+
33
+ inf = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /bebe/}.first
34
+ @tarifas['inf'] = inf ? Price.new((inf/"span.currency").first.inner_text.strip + " " + (inf/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
35
+
36
+ tasas = (p_html/"li.taxes-price").empty? ? (p_html/"li[@class='taxDetail.OTHER-price']").first : (p_html/"li.taxes-price").first
37
+ @tarifas['tasas'] = tasas ? Price.new((tasas/"span.currency").first.inner_text.strip + " " + (tasas/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
38
+
39
+ cargos = (p_html/"li.charges-price").first
40
+ @tarifas['cargos'] = cargos ? Price.new((cargos/"span.currency").first.inner_text.strip + " " + (cargos/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
41
+
42
+ afip = (p_html/"li[@class='taxDetail.ZK-price']").first
43
+ @tarifas['afip'] = afip ? Price.new((afip/"span.currency").first.inner_text.strip + " " + (afip/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
44
+
45
+ @tarifas['encargos'] = Price.new("$ 0",true)
46
+
47
+ campo = (p_html/"li").empty? ? "total" : "fare"
48
+ @tarifas['total'] = (p_html/"li.#{campo}-price span.currency").empty? ? Price.new("$ 0",true) : Price.new((p_html/"li.#{campo}-price span.currency").first.inner_text.strip + " " + (p_html/"li.#{campo}-price span.amount").first.inner_text.strip)
49
+ end
50
+
51
+ def sin_diferencia(p_html)
52
+ @tarifas = Hash.new
53
+ @tarifas['tarifa_adulto_dolar'] = Price.new("$ 0",true)
54
+ if (p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.currency").first
55
+ @tarifas['tarifa_adulto'] = Price.new((p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.currency").first.inner_text.strip + " " + (p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.amount").first.inner_text.strip)
56
+ else
57
+ @tarifas['tarifa_adulto'] = @tarifas['tarifa_adulto_dolar']
58
+ end
59
+
60
+ adt = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /adulto/}.first
61
+ @tarifas['adt'] = adt ? Price.new((adt/"span.currency").first.inner_text.strip + " " + (adt/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
62
+
63
+ cnn = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /nino/}.first
64
+ @tarifas['cnn'] = cnn ? Price.new((cnn/"span.currency").first.inner_text.strip + " " + (cnn/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
65
+
66
+ inf = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /bebe/}.first
67
+ @tarifas['inf'] = inf ? Price.new((inf/"span.currency").first.inner_text.strip + " " + (inf/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
68
+
69
+ tasas = (p_html/"li.taxes-price").empty? ? (p_html/"li[@class='taxDetail.OTHER-price']").first : (p_html/"li.taxes-price").first
70
+ @tarifas['tasas'] = tasas ? Price.new((tasas/"span.currency").first.inner_text.strip + " " + (tasas/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
71
+
72
+ cargos = (p_html/"li.charges-price").first
73
+ @tarifas['cargos'] = cargos ? Price.new((cargos/"span.currency").first.inner_text.strip + " " + (cargos/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
74
+
75
+ afip = (p_html/"li[@class='taxDetail.ZK-price']").first
76
+ @tarifas['afip'] = afip ? Price.new((afip/"span.currency").first.inner_text.strip + " " + (afip/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
77
+
78
+ @tarifas['encargos'] = Price.new("$ 0",true)
79
+
80
+ campo = (p_html/"li").empty? ? "total" : "fare"
81
+ @tarifas['total'] = (p_html/"li.#{campo}-price span.currency").empty? ? Price.new("$ 0",true) : Price.new((p_html/"li.#{campo}-price span.currency").first.inner_text.strip + " " + (p_html/"li.#{campo}-price span.amount").first.inner_text.strip)
82
+ end
83
+ end
@@ -0,0 +1,171 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require_relative 'data/data'
3
+ class ResultsCluster
4
+
5
+ attr_accessor :ida, :vuelta, :tarifas, :idas, :vueltas
6
+
7
+ def initialize(itinerario,html,page = 0)
8
+ eval "#{itinerario.downcase}(html)"
9
+ self.load_prices((html/"div.fare-container"))
10
+ end
11
+
12
+ def roundtrip(html)
13
+ self.load_data_from((html/"div.itineraries div[@class='sub-cluster outbound']"))
14
+ self.load_data_to((html/"div.itineraries div[@class='sub-cluster inbound']"))
15
+ end
16
+ def oneway(html)
17
+ self.load_data_from((html/"div.itineraries//div[@class='sub-cluster outbound']"))
18
+ @nro_vuelo_vuelta = -1
19
+ end
20
+ def multipledestinations(html)
21
+ self.load_data_from((html/"div.itineraries//div[@class='sub-cluster multiple']"))
22
+ self.load_data_to((html/"div.itineraries//div[@class='sub-cluster multiple']").last)
23
+ end
24
+ def load_data_from(div_datos)
25
+ @idas = Array.new
26
+ (div_datos/"li.itinerary").each do |div_datos_ida|
27
+ duracion = (div_datos_ida/"li.time").inner_text.strip
28
+ origen = (div_datos/"span.city-departure").first.inner_text.gsub(/,/,'').strip.no_accents
29
+ destino= (div_datos/"span.city-arrival").first.inner_text.gsub(/,/,'').strip.no_accents
30
+ origen_iata = (div_datos/"a")[0].inner_text.strip
31
+ destino_iata = (div_datos/"a")[1].inner_text.strip
32
+ fecha = (div_datos/"span.date").first.empty? ? (div_datos_ida/"li.date").first.inner_text.strip.no_accents : (div_datos/"span.date").first.inner_text.strip.no_accents
33
+ escala = (div_datos_ida/"li.stops/a").inner_text.strip.empty? ? "Sin escalas" : (div_datos_ida/"li.stops/a").inner_text.to_i
34
+ aerolinea = Array.new
35
+ i = 0
36
+ (div_datos_ida/"li.airlinesShort//img").each do |aer|
37
+ aerolinea << aer.attributes['src'].match(/(..).png/)[1].upcase
38
+ i = i + 1
39
+ end
40
+ (div_datos_ida/"li.airlines//img").each do |aer|
41
+ aerolinea << aer.attributes['src'].match(/(..).png/)[1].upcase
42
+ i = i + 1
43
+ end
44
+ hou_sal_ida = Time.parse((div_datos_ida/"li.leave span.hour").inner_text.strip)
45
+ hou_lle_ida = Time.parse((div_datos_ida/"li.arrive span.hour").inner_text.strip)
46
+ @idas << DataCluster.new(origen,destino,fecha, aerolinea, escala_to_i(escala),origen_iata,destino_iata,hou_sal_ida,hou_lle_ida,duracion)
47
+ end
48
+ @nro_vuelo_ida = 0
49
+ @ida = @idas[@nro_vuelo_ida]
50
+ end
51
+ def load_data_to(div_datos)
52
+ @vueltas = Array.new
53
+ (div_datos/"li.itinerary").each do |div_datos_vuelta|
54
+ duracion = (div_datos_vuelta/"li.time").inner_text.strip
55
+ origen = (div_datos/"span.city-departure").first.inner_text.gsub(/,/,'').strip.no_accents
56
+ destino= (div_datos/"span.city-arrival").first.inner_text.gsub(/,/,'').strip.no_accents
57
+ origen_iata = (div_datos/"a")[0].inner_text.strip
58
+ destino_iata = (div_datos/"a")[1].inner_text.strip
59
+ fecha = (div_datos/"span.date").last.empty? ? (div_datos_vuelta/"li.date").last.inner_text.strip.no_accents : (div_datos/"span.date").last.inner_text.strip.no_accents
60
+ escala = (div_datos_vuelta/"li.stops/a").inner_text.strip.empty? ? "Sin escalas" : (div_datos_vuelta/"li.stops/a").inner_text.to_i
61
+ aerolinea = Array.new
62
+ i = 0
63
+ (div_datos_vuelta/"li.airlinesShort//img").each do |aer|
64
+ aerolinea << aer.attributes['src'].match(/(..).png/)[1].upcase
65
+ i = i + 1
66
+ end
67
+ (div_datos_vuelta/"li.airlines//img").each do |aer|
68
+ aerolinea << aer.attributes['src'].match(/(..).png/)[1].upcase
69
+ i = i + 1
70
+ end
71
+ hou_sal_ida = Time.parse((div_datos_vuelta/"li.leave span.hour").inner_text.strip)
72
+ hou_lle_ida = Time.parse((div_datos_vuelta/"li.arrive span.hour").inner_text.strip)
73
+ @vueltas << DataCluster.new(origen,destino,fecha, aerolinea, escala_to_i(escala),origen_iata,destino_iata,hou_sal_ida,hou_lle_ida,duracion)
74
+ end
75
+ @nro_vuelo_vuelta = 0
76
+ @vuelta = @vueltas[@nro_vuelo_vuelta]
77
+ end
78
+
79
+ def load_prices(p_html)
80
+
81
+ @tarifas = Hash.new
82
+ @tarifas['tarifa_adulto_dolar'] = Price.new((p_html/"span.price-currency span.currency").first.inner_text.strip + " " + (p_html/"span.price-currency span.amount").first.inner_text.strip)
83
+ if (p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.currency").first
84
+ @tarifas['tarifa_adulto'] = Price.new((p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.currency").first.inner_text.strip + " " + (p_html/"span[@class='price-currency #{Helpers.currency(AllPages.site)} '] span.amount").first.inner_text.strip)
85
+ else
86
+ @tarifas['tarifa_adulto'] = @tarifas['tarifa_adulto_dolar']
87
+ end
88
+
89
+ adt = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /adulto/}.first
90
+ @tarifas['adt'] = adt ? Price.new((adt/"span.currency").first.inner_text.strip + " " + (adt/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
91
+
92
+ cnn = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /nino/}.first
93
+ @tarifas['cnn'] = cnn ? Price.new((cnn/"span.currency").first.inner_text.strip + " " + (cnn/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
94
+
95
+ inf = (p_html/"li").select{|li| li.inner_text.no_accents.downcase =~ /bebe/}.first
96
+ @tarifas['inf'] = inf ? Price.new((inf/"span.currency").first.inner_text.strip + " " + (inf/"span.amount").first.inner_text.strip) : Price.new("$ 0",true)
97
+
98
+ tasas = (p_html/"li.taxes-price").empty? ? (p_html/"li[@class='taxDetail.OTHER-price']").first : (p_html/"li.taxes-price").first
99
+ @tarifas['tasas'] = tasas ? Price.new((tasas/"span.currency").first.inner_text.strip + " " + (tasas/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
100
+
101
+ cargos = (p_html/"li.charges-price").first
102
+ @tarifas['cargos'] = cargos ? Price.new((cargos/"span.currency").first.inner_text.strip + " " + (cargos/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
103
+
104
+ afip = (p_html/"li[@class='taxDetail.ZK-price']").first
105
+ @tarifas['afip'] = afip ? Price.new((afip/"span.currency").first.inner_text.strip + " " + (afip/"span.amount").first.inner_text.strip,true) : Price.new("$ 0",true)
106
+
107
+ @tarifas['encargos'] = Price.new("$ 0",true)
108
+
109
+ campo = (p_html/"li").empty? ? "total" : "fare"
110
+ @tarifas['total'] = (p_html/"li.#{campo}-price span.currency").empty? ? Price.new("$ 0",true) : Price.new((p_html/"li.#{campo}-price span.currency").first.inner_text.strip + " " + (p_html/"li.#{campo}-price span.amount").first.inner_text.strip)
111
+ end
112
+
113
+ def validarSumaDesgloce(linea = "total|tarifa_adulto")
114
+
115
+ sumaTarifas = 0
116
+ @tarifas.each_pair do |key,tarifa|
117
+ if key !~ /#{linea}/
118
+ sumaTarifas += tarifa.valor
119
+ end
120
+ if @tarifas['total'] and (tarifa.valor > @tarifas['total'].valor) and (linea !~ /tarifa_adulto/)
121
+ true.should be_true
122
+ end
123
+ end
124
+
125
+ if @tarifas['total'] and ((sumaTarifas.to_i - @tarifas['total'].valor.to_i) > 3)
126
+ true.should be_true
127
+ end
128
+
129
+ end
130
+ def validarEcuacionTarifasPorCantidadDePasajeros(cant)
131
+ unless @tarifas['adt'].valor.zero?
132
+ (@tarifas['adt'].valor == @tarifas['tarifa_adulto'].valor * cant).should be_true
133
+ end
134
+ end
135
+ def validarResolucionAFIP
136
+ (@tarifas['total'] * 20 / 100).truncate + 1 == @tarifas['afip']
137
+ end
138
+ def total_escalas()
139
+ vueltas = @vueltas ? @vueltas.collect{|vuelta| vuelta.escalas} : []
140
+ (vueltas + @idas.collect{|vuelta| vuelta.escalas}).sort
141
+ end
142
+
143
+ def duracion
144
+ menor_ida = menor_duracion(@idas.collect{|ida| ida.duracion})
145
+ menor_vuelta = @vueltas ? menor_duracion(@vueltas.collect{|ida| ida.duracion}) : 0
146
+
147
+ return menor_vuelta + menor_ida
148
+ end
149
+
150
+ def escala_to_i(escala)
151
+ return 0 if escala.to_s =~ /(solo vuelo directo)|(Sin escalas)|(Sem escalas)|(Soamente v.o directo)|(Vuelo Directo)/i
152
+ return escala.to_s.gsub(/\D/,'').to_i
153
+ end
154
+
155
+ def menor_duracion(rutas)
156
+ totales = []
157
+ rutas.each do |custom|
158
+ if custom.match("^(.*)h (.*)m$")
159
+ total = custom.match("^(.*)h (.*)m$")[1].to_i * 60
160
+ total += custom.match("^(.*)h (.*)m$")[2].to_i
161
+ elsif custom.match("^(.*)h$")
162
+ total = custom.match("^(.*)h$")[1].to_i * 60
163
+ else
164
+ total = custom.match("^(.*)m$")[1].to_i
165
+ end
166
+ totales << total
167
+ end
168
+ return totales.sort.first
169
+ end
170
+
171
+ end