Class: Hbtrack::ShowCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/hbtrack/command/show_command.rb

Overview

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

Instance Method Summary collapse

Methods inherited from Command

#help, #local_store

Constructor Details

#initialize(store_path, options) ⇒ ShowCommand

Returns a new instance of ShowCommand.



11
12
13
# File 'lib/hbtrack/command/show_command.rb', line 11

def initialize(store_path, options)
  super(store_path, options)
end

Instance Method Details

#create_option_parserObject



20
21
22
23
24
# 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

#executeObject



15
16
17
18
# 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) ⇒ Object



34
35
36
37
# 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) ⇒ Object



26
27
28
29
30
31
32
# 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