Class: Hbtrack::ShowCommand
- Defined in:
- lib/hbtrack/command/show_command.rb
Overview
ShowCommand class is responsible for handling ‘hbtrack import` command in CLI
Instance Method Summary collapse
- #create_option_parser ⇒ Object
- #execute ⇒ Object
- #get_entries_from_db(store, habit) ⇒ Object
-
#initialize(store_path, options) ⇒ ShowCommand
constructor
A new instance of ShowCommand.
- #show(store, title) ⇒ Object
Methods inherited from Command
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, ) super(store_path, ) end |
Instance Method Details
#create_option_parser ⇒ Object
20 21 22 23 24 |
# File 'lib/hbtrack/command/show_command.rb', line 20 def create_option_parser OptionParser.new do |opts| opts. = 'Usage: hbtrack show <habit_name>' end end |
#execute ⇒ Object
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 |