module Hbtrack::Util

This class contains the methods that are used to format the progress of a Habit into string

Constants

FONT_COLOR

Public Class Methods

convert_key_to_date(key, no_of_space) click to toggle source

Convert key into date in string form.

@param key [Symbol] The key of the progress in the

form of :'year, month'. Example: :"2017,7"

@param no_of_space [Numeric] number of space to be

added in front

@return [String] a string in date form.

Example

Util.convert_key_to_date(:"2017,7", 0)
#=> "July 2016 : "
# File lib/hbtrack/util.rb, line 51
def convert_key_to_date(key, no_of_space)
  year = key.to_s.split(',')[0]
  ' ' * no_of_space + get_month_from(key) +
    " #{year}" + ' : '
end
get_date_from(key:) click to toggle source
# File lib/hbtrack/util.rb, line 57
def get_date_from(key:)
  date_component = key.to_s.split(',').map(&:to_i)
  Date.new(date_component[0], date_component[1], 1)
end
get_month_from(key) click to toggle source

Get the month in string form from given key

@param key [Symbol] The key of the progress @return [String] month

Example

Util.get_month_from(:"2017,7")
#=> "July"
# File lib/hbtrack/util.rb, line 71
def get_month_from(key)
  key = key.to_s.split(',')
  Date::MONTHNAMES[key[1].to_i]
end
title(string) click to toggle source

Format the string with title style.

@param string [String] the string to be styled as title @return [Nil]

Example

puts Util.title("Title")
# Title
# -----
#=> nil
# File lib/hbtrack/util.rb, line 34
def title(string)
  string + "\n" +
    '-' * string.length + "\n"
end