yahoo_weather 1.0.0

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 (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +94 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +51 -0
  8. data/Rakefile +32 -0
  9. data/config/locales/en.yml +69 -0
  10. data/config/locales/ru.yml +69 -0
  11. data/lib/generators/yahoo_weather/copy_locale_generator.rb +11 -0
  12. data/lib/yahoo_weather/astronomy.rb +8 -0
  13. data/lib/yahoo_weather/atmosphere.rb +29 -0
  14. data/lib/yahoo_weather/client.rb +42 -0
  15. data/lib/yahoo_weather/condition.rb +15 -0
  16. data/lib/yahoo_weather/forecast.rb +17 -0
  17. data/lib/yahoo_weather/location.rb +9 -0
  18. data/lib/yahoo_weather/response.rb +54 -0
  19. data/lib/yahoo_weather/units.rb +13 -0
  20. data/lib/yahoo_weather/version.rb +3 -0
  21. data/lib/yahoo_weather/wind.rb +55 -0
  22. data/lib/yahoo_weather.rb +18 -0
  23. data/test/dummy/README.rdoc +28 -0
  24. data/test/dummy/Rakefile +6 -0
  25. data/test/dummy/app/assets/images/.keep +0 -0
  26. data/test/dummy/app/assets/javascripts/application.js +13 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/test/dummy/app/controllers/application_controller.rb +5 -0
  29. data/test/dummy/app/controllers/concerns/.keep +0 -0
  30. data/test/dummy/app/helpers/application_helper.rb +2 -0
  31. data/test/dummy/app/mailers/.keep +0 -0
  32. data/test/dummy/app/models/.keep +0 -0
  33. data/test/dummy/app/models/concerns/.keep +0 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/bin/bundle +3 -0
  36. data/test/dummy/bin/rails +4 -0
  37. data/test/dummy/bin/rake +4 -0
  38. data/test/dummy/config/application.rb +23 -0
  39. data/test/dummy/config/boot.rb +5 -0
  40. data/test/dummy/config/database.yml +25 -0
  41. data/test/dummy/config/environment.rb +5 -0
  42. data/test/dummy/config/environments/development.rb +29 -0
  43. data/test/dummy/config/environments/production.rb +80 -0
  44. data/test/dummy/config/environments/test.rb +36 -0
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  47. data/test/dummy/config/initializers/inflections.rb +16 -0
  48. data/test/dummy/config/initializers/mime_types.rb +5 -0
  49. data/test/dummy/config/initializers/secret_token.rb +12 -0
  50. data/test/dummy/config/initializers/session_store.rb +3 -0
  51. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/test/dummy/config/locales/en.yml +23 -0
  53. data/test/dummy/config/routes.rb +56 -0
  54. data/test/dummy/config.ru +4 -0
  55. data/test/dummy/db/test.sqlite3 +0 -0
  56. data/test/dummy/lib/assets/.keep +0 -0
  57. data/test/dummy/log/.keep +0 -0
  58. data/test/dummy/log/development.log +0 -0
  59. data/test/dummy/log/test.log +55 -0
  60. data/test/dummy/public/404.html +58 -0
  61. data/test/dummy/public/422.html +58 -0
  62. data/test/dummy/public/500.html +57 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/tmp/cache/83D/EE0/yahoo_weather_12797168_f +56 -0
  65. data/test/test_helper.rb +17 -0
  66. data/test/yahoo_weather_test.rb +159 -0
  67. data/yahoo_weather.gemspec +22 -0
  68. metadata +202 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24bef4f8f4cdfeacb288198d866be0eda9109e71
4
+ data.tar.gz: b240e2f2fdee92fda21242f9aa9671de6803f60e
5
+ SHA512:
6
+ metadata.gz: 0124bcaf4ba8d5f92393a8f03091ef50eb7330175684398f48a1c25a1088217c1e0c27222bcc38d47cf48077db87f1b90000f78131b68db9817e7c524dee17a0
7
+ data.tar.gz: 48d2b86838ae5d757a59d2a2f261b27bb7244a8b6c292e5a04f6aca834e24ccf201555e052fb3139057732bca7d03887569dd4f851b62a48e0441f8865ed7bc8
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /test/dummy/log/test.log
2
+ /test/dummy/tmp/
3
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yahoo_weather (1.0.0)
5
+ nokogiri
6
+ rails (~> 4.0.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (4.0.0)
12
+ actionpack (= 4.0.0)
13
+ mail (~> 2.5.3)
14
+ actionpack (4.0.0)
15
+ activesupport (= 4.0.0)
16
+ builder (~> 3.1.0)
17
+ erubis (~> 2.7.0)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ activemodel (4.0.0)
21
+ activesupport (= 4.0.0)
22
+ builder (~> 3.1.0)
23
+ activerecord (4.0.0)
24
+ activemodel (= 4.0.0)
25
+ activerecord-deprecated_finders (~> 1.0.2)
26
+ activesupport (= 4.0.0)
27
+ arel (~> 4.0.0)
28
+ activerecord-deprecated_finders (1.0.3)
29
+ activesupport (4.0.0)
30
+ i18n (~> 0.6, >= 0.6.4)
31
+ minitest (~> 4.2)
32
+ multi_json (~> 1.3)
33
+ thread_safe (~> 0.1)
34
+ tzinfo (~> 0.3.37)
35
+ arel (4.0.0)
36
+ atomic (1.1.13)
37
+ builder (3.1.4)
38
+ erubis (2.7.0)
39
+ fakeweb (1.3.0)
40
+ hike (1.2.3)
41
+ i18n (0.6.5)
42
+ mail (2.5.4)
43
+ mime-types (~> 1.16)
44
+ treetop (~> 1.4.8)
45
+ mime-types (1.24)
46
+ mini_portile (0.5.1)
47
+ minitest (4.7.5)
48
+ multi_json (1.7.9)
49
+ nokogiri (1.6.0)
50
+ mini_portile (~> 0.5.0)
51
+ polyglot (0.3.3)
52
+ rack (1.5.2)
53
+ rack-test (0.6.2)
54
+ rack (>= 1.0)
55
+ rails (4.0.0)
56
+ actionmailer (= 4.0.0)
57
+ actionpack (= 4.0.0)
58
+ activerecord (= 4.0.0)
59
+ activesupport (= 4.0.0)
60
+ bundler (>= 1.3.0, < 2.0)
61
+ railties (= 4.0.0)
62
+ sprockets-rails (~> 2.0.0)
63
+ railties (4.0.0)
64
+ actionpack (= 4.0.0)
65
+ activesupport (= 4.0.0)
66
+ rake (>= 0.8.7)
67
+ thor (>= 0.18.1, < 2.0)
68
+ rake (10.1.0)
69
+ sprockets (2.10.0)
70
+ hike (~> 1.2)
71
+ multi_json (~> 1.0)
72
+ rack (~> 1.0)
73
+ tilt (~> 1.1, != 1.3.0)
74
+ sprockets-rails (2.0.0)
75
+ actionpack (>= 3.0)
76
+ activesupport (>= 3.0)
77
+ sprockets (~> 2.8)
78
+ sqlite3 (1.3.8)
79
+ thor (0.18.1)
80
+ thread_safe (0.1.2)
81
+ atomic
82
+ tilt (1.4.1)
83
+ treetop (1.4.15)
84
+ polyglot
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (0.3.37)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ fakeweb (~> 1.3)
93
+ sqlite3
94
+ yahoo_weather!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Ildar Manzhikov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # yahoo_weather
2
+
3
+ A Ruby object-oriented interface to the Yahoo! Weather feed.
4
+
5
+ It supports caching and i18n.
6
+
7
+ ## Installation
8
+
9
+ $ gem install yahoo_weather
10
+
11
+
12
+ Include in your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'yahoo_weather'
16
+ ```
17
+
18
+ ## API
19
+
20
+ http://developer.yahoo.com/weather/
21
+
22
+ ## Example
23
+
24
+ ```ruby
25
+ client = YahooWeather::Client.new
26
+ response = client.fetch(12797168)
27
+ response.units.temperature # "F"
28
+ response.condition.temp # 60
29
+ response.wind.direction # 110
30
+ response.wind.direction('string') # "ESE"
31
+ response.condition.code # 29
32
+ response.condition.code('string') # "Partly cloudy (night)"
33
+ ```
34
+
35
+ ## Locales
36
+
37
+ Copy locale command:
38
+
39
+ ```ruby
40
+ rails g yahoo_weather:copy_locale en
41
+ ```
42
+
43
+ ## Available Locales
44
+
45
+ Available locales are:
46
+
47
+ > en, ru
48
+
49
+ ## License
50
+
51
+ MIT License. Copyright 2013 Ildar Manzhikov <manzhikov@gmail.com>. http://manzhikov.com
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'YahooWeather'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,69 @@
1
+ en:
2
+ yahoo_weather:
3
+ wind:
4
+ n: N
5
+ nne: NNE
6
+ ne: NE
7
+ ene: ENE
8
+ e: E
9
+ ese: ESE
10
+ se: SE
11
+ sse: SSE
12
+ s: S
13
+ ssw: SSW
14
+ sw: SW
15
+ wsw: WSW
16
+ w: W
17
+ wnw: WNW
18
+ nw: NW
19
+ nnw: NNW
20
+ code:
21
+ '0': 'Tornado'
22
+ '1': 'Tropical storm'
23
+ '2': 'Hurricane'
24
+ '3': 'Severe thunderstorms'
25
+ '4': 'Thunderstorms'
26
+ '5': 'Mixed rain and snow'
27
+ '6': 'Mixed rain and sleet'
28
+ '7': 'Mixed snow and sleet'
29
+ '8': 'Freezing drizzle'
30
+ '9': 'Drizzle'
31
+ '10': 'Freezing rain'
32
+ '11': 'Showers'
33
+ '12': 'Showers'
34
+ '13': 'Snow flurries'
35
+ '14': 'Light snow showers'
36
+ '15': 'Blowing snow'
37
+ '16': 'Snow'
38
+ '17': 'Hail'
39
+ '18': 'Sleet'
40
+ '19': 'Dust'
41
+ '20': 'Foggy'
42
+ '21': 'Haze'
43
+ '22': 'Smoky'
44
+ '23': 'Blustery'
45
+ '24': 'Windy'
46
+ '25': 'Cold'
47
+ '26': 'Cloudy'
48
+ '27': 'Mostly cloudy (night)'
49
+ '28': 'Mostly cloudy (day)'
50
+ '29': 'Partly cloudy (night)'
51
+ '30': 'Partly cloudy (day)'
52
+ '31': 'Clear (night)'
53
+ '32': 'Sunny'
54
+ '33': 'Fair (night)'
55
+ '34': 'Fair (day)'
56
+ '35': 'Mixed rain and hail'
57
+ '36': 'Hot'
58
+ '37': 'Isolated thunderstorms'
59
+ '38': 'Scattered thunderstorms'
60
+ '39': 'Scattered thunderstorms'
61
+ '40': 'Scattered showers'
62
+ '41': 'Heavy snow'
63
+ '42': 'Scattered snow showers'
64
+ '43': 'Heavy snow'
65
+ '44': 'Partly cloudy'
66
+ '45': 'Thundershowers'
67
+ '46': 'Snow showers'
68
+ '47': 'Isolated thundershowers'
69
+ '3200': 'Not available'
@@ -0,0 +1,69 @@
1
+ ru:
2
+ yahoo_weather:
3
+ wind:
4
+ n: С
5
+ nne: ССВ
6
+ ne: СВ
7
+ ene: ВСВ
8
+ e: В
9
+ ese: ВЮВ
10
+ se: ЮВ
11
+ sse: ЮЮВ
12
+ s: Ю
13
+ ssw: ЮЮЗ
14
+ sw: ЮЗ
15
+ wsw: ЗЮЗ
16
+ w: З
17
+ wnw: ЗСЗ
18
+ nw: СЗ
19
+ nnw: ССЗ
20
+ code:
21
+ '0': 'Торнадо'
22
+ '1': 'Тропический шторм'
23
+ '2': 'Ураган'
24
+ '3': 'Сильный шторм'
25
+ '4': 'Шторм'
26
+ '5': 'Мокрый снег'
27
+ '6': 'Дождь с градом'
28
+ '7': 'Дождь со снегом и градом'
29
+ '8': 'Мороз'
30
+ '9': 'Изморось'
31
+ '10': 'Мороз'
32
+ '11': 'Дождь'
33
+ '12': 'Дождь'
34
+ '13': 'Хлопья снега'
35
+ '14': 'Небольшой снег'
36
+ '15': 'Метель'
37
+ '16': 'Снег'
38
+ '17': 'Град'
39
+ '18': 'Град'
40
+ '19': 'Пыль'
41
+ '20': 'Туман'
42
+ '21': 'Туман'
43
+ '22': 'Туман'
44
+ '23': 'Сильный ветер'
45
+ '24': 'Ветренно'
46
+ '25': 'Холодно'
47
+ '26': 'Облачно'
48
+ '27': 'Ночью переменная облачность'
49
+ '28': 'Переменная облачность'
50
+ '29': 'Ночью ясно'
51
+ '30': 'Ясно'
52
+ '31': 'Облачно'
53
+ '32': 'Солнечно'
54
+ '33': 'Ясно'
55
+ '34': 'Ясно'
56
+ '35': 'Переменный дождь с градом'
57
+ '36': 'Жарко'
58
+ '37': 'Местами сильный ветер'
59
+ '38': 'Переменный сильный ветер'
60
+ '39': 'Переменный сильный ветер'
61
+ '40': 'Кратковременные дожди'
62
+ '41': 'Обильный снегопад'
63
+ '42': 'Снег'
64
+ '43': 'Обильный снегопад'
65
+ '44': 'Ясно'
66
+ '45': 'Шторм'
67
+ '46': 'Снег'
68
+ '47': 'Местами дожди'
69
+ '3200': 'Нет сведений'
@@ -0,0 +1,11 @@
1
+ module YahooWeather
2
+ module Generators
3
+ class CopyLocaleGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(__FILE__)
5
+ argument :locale, type: :string, default: 'en'
6
+ def copy_locale
7
+ copy_file "../../../../config/locales/#{locale.underscore}.yml", "config/locales/yahoo_weather.#{locale.underscore}.yml"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class YahooWeather::Astronomy
2
+ attr_reader :sunrise, :sunset
3
+
4
+ def initialize(payload)
5
+ @sunrise = Time.parse(payload['sunrise'])
6
+ @sunset = Time.parse(payload['sunset'])
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ class YahooWeather::Atmosphere
2
+ class Barometer
3
+ STEADY = 'steady'
4
+ RISING = 'rising'
5
+ FALLING = 'falling'
6
+
7
+ # lists all possible barometer constants
8
+ ALL = [ STEADY, RISING, FALLING ]
9
+ end
10
+
11
+ attr_reader :humidity, :visibility, :pressure, :barometer
12
+
13
+ def initialize(payload)
14
+ @humidity = payload['humidity'].to_i
15
+ @visibility = payload['visibility'].to_f
16
+ @pressure = payload['pressure'].to_f
17
+
18
+ # map barometric pressure direction to appropriate constant
19
+ @barometer = nil
20
+ case payload['rising'].to_i
21
+ when 0
22
+ @barometer = Barometer::STEADY
23
+ when 1
24
+ @barometer = Barometer::RISING
25
+ when 2
26
+ @barometer = Barometer::FALLING
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ class YahooWeather::Client
2
+ attr_reader :units, :woeid
3
+
4
+ def fetch(woeid, units = YahooWeather::Units::FAHRENHEIT)
5
+ @units = units
6
+ @woeid = woeid
7
+ doc = Nokogiri::XML(read_xml)
8
+ YahooWeather::Response.new(doc)
9
+ end
10
+
11
+ private
12
+ def get_url
13
+ "http://weather.yahooapis.com/forecastrss?w=#{@woeid}&u=#{@units}"
14
+ end
15
+
16
+ def read_xml
17
+ save_cache unless Rails.cache.exist? cache_key
18
+ read_cache
19
+ end
20
+
21
+ def fetch_xml
22
+ begin
23
+ response = open(get_url)
24
+ rescue OpenURI::HTTPError => e
25
+ raise RuntimeError.new("Failed to get weather. Got a bad status code #{e.message}")
26
+ end
27
+
28
+ response.read
29
+ end
30
+
31
+ def save_cache
32
+ Rails.cache.write(cache_key, fetch_xml, expires_in: 1.minute)
33
+ end
34
+
35
+ def read_cache
36
+ Rails.cache.read cache_key
37
+ end
38
+
39
+ def cache_key
40
+ "yahoo_weather_#{@woeid}_#{@units}"
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ class YahooWeather::Condition
2
+ attr_reader :text, :temp, :date
3
+
4
+ def initialize(payload)
5
+ @text = payload['text']
6
+ @code = payload['code'].to_i
7
+ @temp = payload['temp'].to_i
8
+ @date = Time.parse(payload['date'])
9
+ end
10
+
11
+ def code(u='integer')
12
+ return @code if u == 'integer'
13
+ YahooWeather.code_string(@code)
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ class YahooWeather::Forecast
2
+ attr_reader :date, :high, :low, :text, :day
3
+
4
+ def initialize(payload)
5
+ @date = Date.parse(payload['date'])
6
+ @text = payload['text']
7
+ @day = payload['day']
8
+ @code = payload['code'].to_i
9
+ @high = payload['high'].to_i
10
+ @low = payload['low'].to_i
11
+ end
12
+
13
+ def code(u='integer')
14
+ return @code if u == 'integer'
15
+ YahooWeather.code_string(@code)
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ class YahooWeather::Location
2
+ attr_reader :city, :region, :country
3
+
4
+ def initialize(payload)
5
+ @city = payload['city']
6
+ @region = payload['region']
7
+ @country = payload['country']
8
+ end
9
+ end
@@ -0,0 +1,54 @@
1
+ class YahooWeather::Response
2
+ attr_reader :doc, :title, :link, :description,
3
+ :language, :last_build_date, :ttl,
4
+ :lat, :long
5
+
6
+ def initialize(doc)
7
+ @doc = doc
8
+ @title = get_text('item/title')
9
+ @link = get_text('link')
10
+ @description = get_text('description')
11
+ @language = get_text('language')
12
+ @last_build_date = Time.parse(get_text('lastBuildDate'))
13
+ @ttl = get_text('ttl').to_i
14
+ @lat = get_text('item/geo|lat').to_f
15
+ @long = get_text('item/geo|long').to_f
16
+ end
17
+
18
+ def location
19
+ YahooWeather::Location.new(@doc.at('yweather|location'))
20
+ end
21
+
22
+ def units
23
+ YahooWeather::Units.new(@doc.at('yweather|units'))
24
+ end
25
+
26
+ def astronomy
27
+ YahooWeather::Astronomy.new(@doc.at('yweather|astronomy'))
28
+ end
29
+
30
+ def atmosphere
31
+ YahooWeather::Atmosphere.new(@doc.at('yweather|atmosphere'))
32
+ end
33
+
34
+ def condition
35
+ YahooWeather::Condition.new(@doc.at('item/yweather|condition'))
36
+ end
37
+
38
+ def wind
39
+ YahooWeather::Wind.new(@doc.at('yweather|wind'))
40
+ end
41
+
42
+ def forecasts
43
+ forecasts = []
44
+ @doc.search('item/yweather|forecast').each do |forecast|
45
+ forecasts << YahooWeather::Forecast.new(forecast)
46
+ end
47
+ forecasts
48
+ end
49
+
50
+ private
51
+ def get_text(tag_name)
52
+ @doc.at(tag_name).children.text
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ class YahooWeather::Units
2
+ FAHRENHEIT = 'f'
3
+ CELSIUS = 'c'
4
+
5
+ attr_reader :temperature, :distance, :pressure, :speed
6
+
7
+ def initialize(payload)
8
+ @temperature = payload['temperature']
9
+ @distance = payload['distance']
10
+ @pressure = payload['pressure']
11
+ @speed = payload['speed']
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module YahooWeather
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,55 @@
1
+ class YahooWeather::Wind
2
+ attr_reader :chill, :speed
3
+
4
+ def initialize(payload)
5
+ @chill = payload['chill'].to_i
6
+ @direction = payload['direction'].to_i
7
+ @speed = payload['speed'].to_f
8
+ end
9
+
10
+ def direction(u='integer')
11
+ return @direction if u == 'integer'
12
+
13
+ case @direction
14
+ when 0..11
15
+ direction_string(:n)
16
+ when 12..33
17
+ direction_string(:nne)
18
+ when 34..56
19
+ direction_string(:ne)
20
+ when 57..78
21
+ direction_string(:ene)
22
+ when 79..101
23
+ direction_string(:e)
24
+ when 102..123
25
+ direction_string(:ese)
26
+ when 124..146
27
+ direction_string(:se)
28
+ when 147..168
29
+ direction_string(:sse)
30
+ when 169..191
31
+ direction_string(:s)
32
+ when 192..213
33
+ direction_string(:ssw)
34
+ when 214..236
35
+ direction_string(:sw)
36
+ when 237..258
37
+ direction_string(:wsw)
38
+ when 259..281
39
+ direction_string(:w)
40
+ when 282..303
41
+ direction_string(:wnw)
42
+ when 304..326
43
+ direction_string(:nw)
44
+ when 327..348
45
+ direction_string(:nnw)
46
+ when 349..360
47
+ direction_string(:n)
48
+ end
49
+ end
50
+
51
+ private
52
+ def direction_string(name)
53
+ I18n.t name, scope: [:yahoo_weather, :wind], default: name.to_s.upcase
54
+ end
55
+ end
@@ -0,0 +1,18 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ require 'yahoo_weather/client'
5
+ require 'yahoo_weather/response'
6
+ require 'yahoo_weather/wind'
7
+ require 'yahoo_weather/atmosphere'
8
+ require 'yahoo_weather/astronomy'
9
+ require 'yahoo_weather/condition'
10
+ require 'yahoo_weather/forecast'
11
+ require 'yahoo_weather/location'
12
+ require 'yahoo_weather/units'
13
+
14
+ module YahooWeather
15
+ def self.code_string(id)
16
+ I18n.t id, scope: [:yahoo_weather, :code]
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks