class WeatherCard::FiveLines
a class for creating weather cards to be easily and consistently displayed each card type will be unique to the data it displays
Attributes
day[RW]
|day | |H:xxx L:xxx| |shortdetail| |xx wind | |h:xxx p:xxx|
Public Class Methods
all()
click to toggle source
# File lib/weathercard.rb, line 36 def self.all @@all end
display()
click to toggle source
# 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()
click to toggle source
# File lib/weathercard.rb, line 28 def self.horizontal @@horizontal end
length()
click to toggle source
# File lib/weathercard.rb, line 24 def self.length @@length end
vertical()
click to toggle source
# File lib/weathercard.rb, line 32 def self.vertical @@vertical end
Public Instance Methods
line_five()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/weathercard.rb, line 41 def line_one line_end end
line_seven()
click to toggle source
# File lib/weathercard.rb, line 84 def line_seven line_one end
line_six()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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