class Hbtrack::ShowCommand

ShowCommand class is responsible for handling `hbtrack import` command in CLI

Public Class Methods

new(store_path, options) click to toggle source
Calls superclass method Hbtrack::Command::new
# File lib/hbtrack/command/show_command.rb, line 11
def initialize(store_path, options)
  super(store_path, options)
end

Public Instance Methods

create_option_parser() click to toggle source
# File lib/hbtrack/command/show_command.rb, line 20
def create_option_parser
  OptionParser.new do |opts|
    opts.banner = 'Usage: hbtrack show <habit_name>'
  end
end
execute() click to toggle source
Calls superclass method Hbtrack::Command#execute
# File lib/hbtrack/command/show_command.rb, line 15
def execute
  return show(local_store, @names[0]) if @names[0]
  super
end
get_entries_from_db(store, habit) click to toggle source
# File lib/hbtrack/command/show_command.rb, line 34
def get_entries_from_db(store, habit)
  entries = store.get_entries_of(habit[:id]).all
  entries.group_by { |e| e[:timestamp].strftime('%Y-%m') }
end
show(store, title) click to toggle source
# File lib/hbtrack/command/show_command.rb, line 26
def show(store, title)
  habit = store.get_habit_by_title(title)
  return ErrorHandler.raise_habit_not_found(title) unless habit

  entries = get_entries_from_db(store, habit)
  Hbtrack::CLI::View.show_habit(habit, entries)
end