Class: WeatherCard::FiveLines
Overview
a class for creating weather cards to be easily and consistently displayed each card type will be unique to the data it displays
Constant Summary
collapse
- @@all =
[]
- @@length =
11
- @@horizontal =
'-'.colorize(:light_yellow)
- @@vertical =
'|'.colorize(:light_yellow)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
reset
#initialize, #line_end, #line_intermediate, #return_spaces
Instance Attribute Details
#day ⇒ Object
15
16
17
|
# File 'lib/weathercard.rb', line 15
def day
@day
end
|
Class Method Details
.all ⇒ Object
36
37
38
|
# File 'lib/weathercard.rb', line 36
def self.all
@@all
end
|
.display ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/weathercard.rb', line 88
def self.display
row1 = ''
row2 = ''
row3 = ''
row4 = ''
row5 = ''
row6 = ''
row7 = ''
@@all.each do |day|
row1 += day.line_one
row2 += day.line_two
row3 += day.line_three
row4 += day.line_four
row5 += day.line_five
row6 += day.line_six
row7 += day.line_seven
end
puts row1
puts row2
puts row3
puts row4
puts row5
puts row6
puts row7
end
|
.horizontal ⇒ Object
28
29
30
|
# File 'lib/weathercard.rb', line 28
def self.horizontal
@@horizontal
end
|
.length ⇒ Object
24
25
26
|
# File 'lib/weathercard.rb', line 24
def self.length
@@length
end
|
.vertical ⇒ Object
32
33
34
|
# File 'lib/weathercard.rb', line 32
def self.vertical
@@vertical
end
|
Instance Method Details
#line_five ⇒ Object
70
71
72
73
74
75
|
# File 'lib/weathercard.rb', line 70
def line_five
str_length = day.wind_magnitude.length + day.wind_direction.length + day.wind_units.length
remainder = @@length - str_length
spaces = ' ' * (remainder - 1)
"#{@@vertical}#{day.wind_direction} #{day.wind_magnitude}#{day.wind_units}#{spaces}#{@@vertical}"
end
|
#line_four ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/weathercard.rb', line 59
def line_four
str_length = day.short_detail.length
if str_length < @@length
remainder = @@length - str_length
spaces = ' ' * (remainder)
else
spaces = ''
end
"#{@@vertical}#{day.short_detail.slice(0..10)}#{spaces}#{@@vertical}"
end
|
#line_one ⇒ Object
41
42
43
|
# File 'lib/weathercard.rb', line 41
def line_one
line_end
end
|
#line_seven ⇒ Object
84
85
86
|
# File 'lib/weathercard.rb', line 84
def line_seven
line_one
end
|
#line_six ⇒ Object
77
78
79
80
81
82
|
# File 'lib/weathercard.rb', line 77
def line_six
str_length = [day.precipitation.length,3].min + [day.humidity.length,3].min + 4
remainder = @@length - str_length
spaces = ' ' * (remainder)
"#{@@vertical}h:#{day.humidity.slice(0..2)}#{spaces}p:#{day.precipitation.slice(0..2)}#{@@vertical}"
end
|
#line_three ⇒ Object
52
53
54
55
56
57
|
# File 'lib/weathercard.rb', line 52
def line_three
str_length = day.min.length + day.max.length + 4
remainder = @@length - str_length
spaces = ' ' * (remainder)
"#{@@vertical}H:#{day.max.colorize(:light_red)}#{spaces}L:#{day.min.colorize(:light_blue)}#{@@vertical}"
end
|
#line_two ⇒ Object
45
46
47
48
49
50
|
# File 'lib/weathercard.rb', line 45
def line_two
str_length = day.day.length
remainder = @@length - str_length
spaces = ' ' * (remainder)
"#{@@vertical}#{day.day}#{spaces}#{@@vertical}"
end
|