Class: Hbtrack::ImportCommand

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

Overview

ImportCommand 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) ⇒ ImportCommand

Returns a new instance of ImportCommand.



14
15
16
17
# File 'lib/hbtrack/command/import_command.rb', line 14

def initialize(store_path, options)
  @importer = Hbtrack::Importer::HbtrackImporter.new
  super(store_path, options)
end

Instance Method Details

#create_option_parserObject



24
25
26
27
28
29
30
31
# File 'lib/hbtrack/command/import_command.rb', line 24

def create_option_parser
  OptionParser.new do |opts|
    opts.banner = 'Usage: hbtrack import <file_path> <options>'
    opts.on('--streaks', 'Import data from streaks') do
      @importer = Hbtrack::Importer::StreaksImporter.new
    end
  end
end

#executeObject



19
20
21
22
# File 'lib/hbtrack/command/import_command.rb', line 19

def execute
  return import(@names[0])
  super
end

#import(file_path) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/hbtrack/command/import_command.rb', line 33

def import(file_path)
  @importer.import_from(file_path)
  @importer.store_in(local_store)
  Hbtrack::Util.green "Succesfully imported from #{file_path}"
rescue => e
  Hbtrack::Util.red "Error: #{e}"
end