class Hbtrack::ListCommand
Attributes
formatter[R]
month[R]
printer[R]
Public Class Methods
new(store_path, options)
click to toggle source
Calls superclass method
Hbtrack::Command::new
# File lib/hbtrack/command/list_command.rb, line 11 def initialize(store_path, options) @month = Date.today.strftime("%Y,%-m").to_sym super(store_path, options) end
Public Instance Methods
create_option_parser()
click to toggle source
# File lib/hbtrack/command/list_command.rb, line 21 def create_option_parser OptionParser.new do |opts| opts.banner = 'Usage: hbtrack list [<habit_name>] [options]' opts.separator '' opts.separator 'Options:' # TODO: Renamed to better describe the functionality # as in this case user are required toe enter # the input in the form of <year>,<month> opts.on('-m', '--month MONTH', 'List habit(s) according to month provided') do |month| @month = month.to_sym @year, @mon = month.split(',') end opts.on_tail('-h', '--help', 'Prints this help') do puts opts exit end end end
execute()
click to toggle source
Calls superclass method
Hbtrack::Command#execute
# File lib/hbtrack/command/list_command.rb, line 16 def execute return list_from_db(local_store, @names) super end
get_entry_from_db(store, id)
click to toggle source
# File lib/hbtrack/command/list_command.rb, line 58 def get_entry_from_db(store, id) month = @mon.to_i >= 1 ? @mon.to_i : Date.today.month year = @year.to_i >= 1 ? @year.to_i : Date.today.year store.get_entries_of_month(id, month, year) end
get_habits_from_db(store)
click to toggle source
# File lib/hbtrack/command/list_command.rb, line 48 def get_habits_from_db(store) habits = [] entries = {} habits = store.get_all_habits habits.each do |habit| entries[habit[:title]] = get_entry_from_db(store, habit[:id]) end [habits, entries] end
list_from_db(store, names)
click to toggle source
# File lib/hbtrack/command/list_command.rb, line 42 def list_from_db(store, names) habits = [] habits, entries = get_habits_from_db(store) Hbtrack::CLI::View.list_all_habits(habits, entries, @month) end