Class: WeatherJp::Weather

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/weather_jp/weather.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(city, weathers) ⇒ Weather

Returns a new instance of Weather.

Parameters:



27
28
29
30
# File 'lib/weather_jp/weather.rb', line 27

def initialize(city, weathers)
  @city = city
  @weathers = weathers
end

Instance Attribute Details

#cityWeatherJp::City (readonly)

Returns the current value of city.

Returns:



8
9
10
# File 'lib/weather_jp/weather.rb', line 8

def city
  @city
end

#currentWeatherJp::DayWeather (readonly)

Returns the current value of current.

Returns:



8
9
10
# File 'lib/weather_jp/weather.rb', line 8

def current
  @current
end

#day_after_tomorrowWeatherJp::DayWeather (readonly)

Returns the current value of day_after_tomorrow.

Returns:



8
9
10
# File 'lib/weather_jp/weather.rb', line 8

def day_after_tomorrow
  @day_after_tomorrow
end

#todayWeatherJp::DayWeather (readonly)

Returns the current value of today.

Returns:



8
9
10
# File 'lib/weather_jp/weather.rb', line 8

def today
  @today
end

#tomorrowWeatherJp::DayWeather (readonly)

Returns the current value of tomorrow.

Returns:



8
9
10
# File 'lib/weather_jp/weather.rb', line 8

def tomorrow
  @tomorrow
end

#weathersArray<WeatherJp::DayWeather> (readonly) Also known as: day_weathers, to_a

Returns the current value of weathers.

Returns:



8
9
10
# File 'lib/weather_jp/weather.rb', line 8

def weathers
  @weathers
end

Instance Method Details

#each {|WeatherJp::DayWeather| ... } ⇒ WeatherJp::Weather



34
35
36
# File 'lib/weather_jp/weather.rb', line 34

def each(&block)
  each_with_all(&block)
end

#each_with_all {|WeatherJp::DayWeather| ... } ⇒ WeatherJp::Weather



40
41
42
43
# File 'lib/weather_jp/weather.rb', line 40

def each_with_all
  weathers.each {|i| yield i }
  self
end

#each_without_current {|WeatherJp::DayWeather| ... } ⇒ WeatherJp::Weather



47
48
49
50
# File 'lib/weather_jp/weather.rb', line 47

def each_without_current
  except_current.each {|i| yield i }
  self
end

#except_currentArray<WeatherJp::DayWeather>

Except current weather status.

Returns:



54
55
56
# File 'lib/weather_jp/weather.rb', line 54

def except_current
  weathers.reject {|w| w.date_code == -1 }
end

#for(date) ⇒ WeatherJp::DayWeather? Also known as: get_weather

Parameters:

  • date (String, Symbol, Integer)

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/weather_jp/weather.rb', line 60

def for(date)
  case date
  when Date
    raise NotImplementedError
  when :current
    day = 0
  when :today
    day = 1
  when :tomorrow
    day = 2
  when :day_after_tomorrow
    day = 3
  else
    day = date + 1
  end

  weathers[day]
end