Class: Weather::Forecast

Inherits:
Object
  • Object
show all
Defined in:
lib/forecast.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:, temp:, humidity:, description:) ⇒ Forecast

Returns a new instance of Forecast.



9
10
11
12
13
14
15
# File 'lib/forecast.rb', line 9

def initialize (date:, temp:, humidity:, description:)
    @date = date
    @temp = temp
    @humidity = humidity
    @description = description
    save
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



7
8
9
# File 'lib/forecast.rb', line 7

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/forecast.rb', line 7

def description
  @description
end

#humidityObject

Returns the value of attribute humidity.



7
8
9
# File 'lib/forecast.rb', line 7

def humidity
  @humidity
end

#locationObject

Returns the value of attribute location.



7
8
9
# File 'lib/forecast.rb', line 7

def location
  @location
end

#tempObject

Returns the value of attribute temp.



7
8
9
# File 'lib/forecast.rb', line 7

def temp
  @temp
end

Class Method Details

.allObject



44
45
46
# File 'lib/forecast.rb', line 44

def self.all 
    @@all
end

.day_displayObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/forecast.rb', line 21

def self.day_display
    forecast = []

    8.times do
        forecast << @@all.shift
    end
    
    forecast.each do |data|
        puts Terminal::Table.new(
            rows: [
                [data.date, "Temp: #{data.temp} F  Humidity: #{data.humidity}  Sky: #{data.description.to_emoji} #{data.description}"]
            ],
            style: {
                border_i: 'X',
                border_x: '=',
                width: 130
            }
        )
    end

end

.eraseObject



48
49
50
# File 'lib/forecast.rb', line 48

def self.erase
    @@all.clear
end

Instance Method Details

#saveObject



17
18
19
# File 'lib/forecast.rb', line 17

def save
    @@all << self
end