Class: Display
- Inherits:
-
Object
- Object
- Display
- Defined in:
- lib/Display.rb
Overview
The display class interacts with data for the model and presents it in a visually appealing way to the user using colors and tables
Class Method Summary collapse
- .display_records(distance, duration) ⇒ Object
- .display_totals(distance, duration) ⇒ Object
-
.show_activities(user) ⇒ Object
shows list of completed activities.
Class Method Details
.display_records(distance, duration) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/Display.rb', line 45 def self.display_records(distance, duration) font = TTY::Font.new(:straight) rows = [["#{distance}kms", "#{duration}"]] table = Terminal::Table.new :title => font.write("Personal Records").colorize(:magenta), :headings => ['Longest Distance', 'Longest Time'], :rows => rows puts table end |
.display_totals(distance, duration) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/Display.rb', line 38 def self.display_totals(distance, duration) font = TTY::Font.new(:straight) rows = [["#{distance}kms", "#{duration}"]] table = Terminal::Table.new :title => font.write("Activity Totals").colorize(:cyan), :headings => ['Total Distance', 'Total Time'], :rows => rows puts table end |
.show_activities(user) ⇒ Object
shows list of completed activities
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/Display.rb', line 13 def self.show_activities(user) activities = Model.get_activities(user) rows = [] activities.each do |a| row = [a.type, a.distance, a.duration, a.date] # if an activity is completed it will display green if a.completed == 'true' row = row.map do |cell| cell.to_s.colorize(:green) end end # if the activity is incomplete, it will turn red if the date has passed if a.completed == 'false' && is_in_past?(a.date) row = row.map do |cell| cell.to_s.colorize(:red) end end rows << row end table = Terminal::Table.new :title => "Activity Log", :headings => ['Activity', 'Distance', 'Duration', 'Date'], :rows => rows puts table end |