Class: Woli::Cli::Runner

Inherits:
Thor
  • Object
show all
Defined in:
lib/woli/cli/runner.rb,
lib/woli/cli/runner_edit.rb,
lib/woli/cli/runner_init.rb,
lib/woli/cli/runner_list.rb,
lib/woli/cli/runner_notify.rb,
lib/woli/cli/runner_status.rb

Instance Method Summary collapse

Instance Method Details

#edit(fuzzy_date = 'today') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/woli/cli/runner_edit.rb', line 10

def edit(fuzzy_date = 'today')
  date = DateParser.parse_date(fuzzy_date)
  entry = Woli.diary.load_or_create_entry(date)

  temp_file_name = generate_temp_file_name(entry)
  save_text_to_temp_file(entry, temp_file_name)
  edit_file_in_editor(temp_file_name)
  load_text_from_temp_file(entry, temp_file_name)

  entry.persist
rescue ConfigError => e
  raise Thor::Error, e.message
end

#initObject



8
9
10
11
12
13
14
15
# File 'lib/woli/cli/runner_init.rb', line 8

def init
  created_config_file_path = Woli::Config.create_config_file_from_template
  if created_config_file_path
    say "Default config file created at #{created_config_file_path}."
  else
    say "Config file already exists."
  end
end

#listObject



5
6
7
8
9
10
11
# File 'lib/woli/cli/runner_list.rb', line 5

def list
  Woli.diary.all_entries_dates.each do |date|
    say date.strftime('%d-%m-%Y')
  end
rescue ConfigError => e
  raise Thor::Error, e.message
end

#notifyObject



5
6
7
8
9
10
11
12
13
# File 'lib/woli/cli/runner_notify.rb', line 5

def notify
  notify_config = Woli.config['notification']['missing_entries']

  if Woli.diary.missing_entries_count >= notify_config['days']
    `#{notify_config['command']}`
  end
rescue ConfigError => e
  raise Thor::Error, e.message
end

#statusObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/woli/cli/runner_status.rb', line 5

def status
  entries_dates = Woli.diary.all_entries_dates
  date_format = '%d-%m-%Y'

  say "Woli Diary Status"
  say "================="

  if entries_dates.count > 0
    coverage = entries_dates.count / Float(entries_dates.last - entries_dates.first + 1)
    say "First entry: #{entries_dates.first.strftime(date_format)}"
    say "Last entry: #{entries_dates.last.strftime(date_format)}"
    say "Coverage: %2d %" % (coverage * 100).round
    say "Missing entries since the last one: #{Woli.diary.missing_entries_count}"
  else
    say "Diary is empty. Run 'woli help edit' to learn how to create entries."
  end
rescue ConfigError => e
  raise Thor::Error, e.message
end