module Hbtrack::CLI::View

Public Instance Methods

convert_entry_to_view(entry) click to toggle source

Create the string representation of a entry to be presented to the user

# File lib/hbtrack/cli/view.rb, line 60
def convert_entry_to_view(entry)
  max_day_of_month = 31
  index = 0
  result = Array.new(max_day_of_month, ' ')
  entry.each do |e|
    date = e[:timestamp]
    index = date.day
    result[index - 1] = convert_status_to_view(e[:type])
  end
  result.slice!(0, index).join('')
end
convert_status_to_view(status) click to toggle source

Create the string representation of a status and colorized it accordingly

# File lib/hbtrack/cli/view.rb, line 74
def convert_status_to_view(status)
  return Util.green '*' if status.start_with? 'completed'
  return Util.red '*'
end
list_all_habits(habits, entries, month_key) click to toggle source

Create the string output of command `hbtrack list` a.k.a ListCommand.list_all

# File lib/hbtrack/cli/view.rb, line 12
 def list_all_habits(habits, entries, month_key)
   date = Util.get_date_from(key: month_key)
   Util.title(date.strftime('%B %Y')) +
     print_habits(habits, entries)
end
max_char_count(strings) click to toggle source

Iterate through an array of string to find the largest character count from the array of string.

# File lib/hbtrack/cli/view.rb, line 82
def max_char_count(strings)
  strings.map(&:size).max
end
print_entries(entries) click to toggle source

Create the string representation of a hash of entries.

print_entry(period, entry, space) click to toggle source

Create the string representation of an entry with its date period. E.g “September 2017”.

# File lib/hbtrack/cli/view.rb, line 54
def print_entry(period, entry, space)
  "#{period}#{' ' * space} : " + convert_entry_to_view(entry)
end
print_habit(index, title, entry, space = 0) click to toggle source

Create the string representation of a habit and its entries to be presented to the user

print_habits(habits, entries) click to toggle source

Create the string representation of the habits and its entries to be presented to the user

show_habit(habit, entries) click to toggle source
# File lib/hbtrack/cli/view.rb, line 18
def show_habit(habit, entries)
  Util.title(habit[:title]) +
    print_entries(entries)
end