powered_wunderground 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afc0a814a57bb9bbebde58adddc8815000deef44
4
- data.tar.gz: 66863b460785851543b4c35cdb15e7079dd7f3b9
3
+ metadata.gz: 77eb9e77642072172259632e6cf55a7583c4b869
4
+ data.tar.gz: 986569aea6509722dea486c25c7001b625619937
5
5
  SHA512:
6
- metadata.gz: 768ee510d6b838b6170d43878f13053245d1e74f3e3883fae53db93cd3bc0897a6fa59ef711612fa61fc067f7687070a8d711f37b027f4fd5755baaab0d0f5b2
7
- data.tar.gz: 18c29f44f450a11ca25bf4e60e622ddc5242156b25e603b44c827c34263d0e001eeef6588fb090634c1fc95710575c342f4e60e7026c6f1bb0598e803ba9756f
6
+ metadata.gz: e57d95a1bb5feaa3426b722586ed61c10957fe61874476e0582ed49bfc951fb57a2dcb8c0f49593f8c13099db9ba4fab4f544cb835ef5bf941c2f9a439d4faf8
7
+ data.tar.gz: 6752cd8f453b1dd43be409a81aa5e4216a3e1ea217220f23be91857fe62303f67a35db4f23204eb55a92c15afaaa309576adfca890f1d4811764ed928c01cbf3
@@ -1,4 +1,5 @@
1
1
  require 'powered_wunderground/version'
2
+ require 'powered_wunderground/weather_decorator'
2
3
  require 'powered_wunderground/connection'
3
4
  require 'powered_wunderground/response'
4
5
 
@@ -0,0 +1,18 @@
1
+ winds:
2
+ word: Winds
3
+ E: East
4
+ ENE: East-northeast
5
+ ESE: East-southeast
6
+ N: North
7
+ NE: Northeast
8
+ NNE: North-northeast
9
+ NNW: North-northwest
10
+ NW: Northwest
11
+ W: West
12
+ WNW: West-northwest
13
+ WSW: West-southwest
14
+ S: South
15
+ SE: Southeast
16
+ SSE: South-southeast
17
+ SSW: South-southwest
18
+ SW: Southwest
@@ -0,0 +1,18 @@
1
+ winds:
2
+ word: Ventos
3
+ E: Este
4
+ ENE: Este/Nordeste
5
+ ESE: Este/Sudeste
6
+ N: Norte
7
+ NE: Nordeste
8
+ NNE: Norte/Nordeste
9
+ NNO: Norte/Noroeste
10
+ "NO": Noroeste
11
+ O: Oeste
12
+ ONO: Oeste/Noroeste
13
+ OSO: Oeste/Sudoeste
14
+ S: Sul
15
+ SE: Sudeste
16
+ SSE: Sul/Sudeste
17
+ SSO: Sul/Sudoeste
18
+ SO: Sudoeste
@@ -15,10 +15,11 @@ module PoweredWunderground
15
15
 
16
16
  def powered_output
17
17
  {
18
- language_code: language_code,
19
- text: to_s,
18
+ country: country,
20
19
  city: city,
21
- country: country
20
+ language_code: language_code,
21
+ original_text: to_s,
22
+ decorated_text: decorated_text
22
23
  }
23
24
  end
24
25
 
@@ -26,6 +27,10 @@ module PoweredWunderground
26
27
 
27
28
  private
28
29
 
30
+ def decorated_text
31
+ WeatherDecorator.new(language_code, to_s).decorate
32
+ end
33
+
29
34
  def fcttext_field(country)
30
35
  if imperial_system.include? country
31
36
  'fcttext'
@@ -1,3 +1,3 @@
1
1
  module PoweredWunderground
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -0,0 +1,62 @@
1
+ module PoweredWunderground
2
+ class WeatherDecorator
3
+ attr_reader :language_code, :text
4
+
5
+ def initialize(language_code, text)
6
+ @language_code = language_code
7
+ @text = text
8
+ end
9
+
10
+ def decorate
11
+ tokens = text.split('.')
12
+ decorate_temperature_part(tokens)
13
+ decorate_wind_part(tokens)
14
+ "#{tokens.join('.')}."
15
+ end
16
+
17
+ def decorate_temperature_part(tokens)
18
+ temperature_token_index = temperature_token_position(tokens)
19
+ return if temperature_token_index.nil?
20
+ tokens[temperature_token_index].sub!(/ (\d+)F$/, ' \1ºF')
21
+ end
22
+
23
+ def decorate_wind_part(tokens)
24
+ wind_token_index = wind_token_position(tokens)
25
+ return if wind_token_index.nil?
26
+ wind_replacements.each do |replacement|
27
+ tokens[wind_token_index].gsub!(" #{replacement[0]} ", " #{replacement[1]} ")
28
+ end
29
+ tokens[wind_token_index] = wind_pronoum_handling tokens[wind_token_index]
30
+ end
31
+
32
+ def temperature_token_position(tokens)
33
+ tokens.index { |t| t.match /\s\d+(C|F)$/ }
34
+ end
35
+
36
+ def wind_token_position(tokens)
37
+ tokens.index { |t| t.match wind_replacements['word'] }
38
+ end
39
+
40
+ def wind_replacements
41
+ replacements_yaml['winds']
42
+ end
43
+
44
+ def replacements_yaml
45
+ @yaml ||= YAML.load_file(replacement_file)
46
+ end
47
+
48
+ def wind_pronoum_handling(text)
49
+ case language_code
50
+ # replace: a 10 a 15 => de 10 a 15
51
+ when 'pt' then text.gsub(/\s(a)(\s\d+\sa\s\d+)/, ' de\2')
52
+ else text
53
+ end
54
+ end
55
+
56
+ def replacement_file
57
+ file = File.join __dir__, 'replacements', "#{language_code}.yml"
58
+ fail "file not found #{file}" unless File.exist? file
59
+ file
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powered_wunderground
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Carneiro
@@ -99,8 +99,11 @@ files:
99
99
  - lib/powered_wunderground.rb
100
100
  - lib/powered_wunderground/connection.rb
101
101
  - lib/powered_wunderground/language_mapper.rb
102
+ - lib/powered_wunderground/replacements/en.yml
103
+ - lib/powered_wunderground/replacements/pt.yml
102
104
  - lib/powered_wunderground/response.rb
103
105
  - lib/powered_wunderground/version.rb
106
+ - lib/powered_wunderground/weather_decorator.rb
104
107
  - powered_wunderground.gemspec
105
108
  homepage: https://github.com/dcarneiro/powered_wunderground
106
109
  licenses: []