Module: Hbtrack::Util
- Defined in:
- lib/hbtrack/util.rb
Overview
This class contains the methods that are used to format the progress of a Habit into string
Constant Summary collapse
- FONT_COLOR =
{ green: "\e[32m", red: "\e[31m", blue: "\e[34m" }.freeze
Class Method Summary collapse
-
.convert_key_to_date(key, no_of_space) ⇒ String
Convert key into date in string form.
- .get_date_from(key:) ⇒ Object
-
.get_month_from(key) ⇒ String
Get the month in string form from given key.
-
.title(string) ⇒ Nil
Format the string with title style.
Class Method Details
.convert_key_to_date(key, no_of_space) ⇒ String
Convert key into date in string form.
Example
Util.convert_key_to_date(:"2017,7", 0)
#=> "July 2016 : "
51 52 53 54 55 |
# 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:) ⇒ Object
57 58 59 60 |
# 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) ⇒ String
71 72 73 74 |
# 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) ⇒ Nil
34 35 36 37 |
# File 'lib/hbtrack/util.rb', line 34 def title(string) string + "\n" + '-' * string.length + "\n" end |