Module: WeatherInPoland
- Defined in:
- lib/weather_in_poland.rb,
lib/weather_in_poland/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#thumb ⇒ Object
readonly
Returns the value of attribute thumb.
Class Method Summary collapse
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
3 4 5 |
# File 'lib/weather_in_poland.rb', line 3 def city @city end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/weather_in_poland.rb', line 4 def code @code end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
5 6 7 |
# File 'lib/weather_in_poland.rb', line 5 def image @image end |
#thumb ⇒ Object (readonly)
Returns the value of attribute thumb.
6 7 8 |
# File 'lib/weather_in_poland.rb', line 6 def thumb @thumb end |
Class Method Details
.find_city(name = 'Gdynia') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/weather_in_poland.rb', line 8 def self.find_city(name='Gdynia') agent = Mechanize.new page = agent.get("http://weather.yahoo.com/poland/") form = page.form('pform') form.fields.find {|f| f.name == 'location'}.value = name page = agent.submit(form) url = page.uri.to_s near_city = page.parser.xpath('//div[@id="yw-nearstation"]/text()').to_s if near_city.empty? return false else @city = near_city.split(':').last.split(',').first.strip @code = url.split('-').last.to_i return true end end |
.get_image(dane) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/weather_in_poland.rb', line 32 def self.get_image(dane) sun_rise = dane.astronomy.sunrise sun_set = dane.astronomy.sunset if sun_rise.past? && sun_set.future? time_of_day = 'd'; else time_of_day = 'n'; end @thumb = "http://l.yimg.com/a/i/us/nws/weather/gr/#{dane.condition.code.to_s+time_of_day}s.png" @image = "http://l.yimg.com/a/i/us/nws/weather/gr/#{dane.condition.code.to_s+time_of_day}.png" end |
.get_weather(code) ⇒ Object
26 27 28 29 30 |
# File 'lib/weather_in_poland.rb', line 26 def self.get_weather(code) client = YahooWeather::Client.new response = client.lookup_by_woeid(code, YahooWeather::Units::CELSIUS) return response end |