Class: Generator

Inherits:
Thor
  • Object
show all
Defined in:
lib/nikki.rb

Overview

This is the main class that interfaces with Thor's methods and does all the heavy lifting for Nikki. It's a bit of a “God” object. Sorries.

Author:

Instance Method Summary (collapse)

Instance Method Details

- (Object) config

Configure Nikki's settings

Parameters:

  • --editor (String)

    (read_config) Sets Nikki's editor to open journal file

  • --yesterday

    Set `settings` to yesterday

  • --today

    Set `settings` to today

  • --print

    Prints Nikki's configuration settings to STDOUT

  • --latest

    Prints Nikki's latest entries to STDOUT



64
65
66
67
68
69
70
71
72
# File 'lib/nikki.rb', line 64

def config
  settings = read_config
  settings[:editor] = options[:editor] || read_config[:editor]
  settings[:updated] = Date.today-1 if options[:yesterday]
  settings[:updated] = Date.today if options[:today]
  write_config(settings)
  puts settings.to_yaml if options[:print]
  puts latest if options[:latest]
end

- (Object) new(*args)

Add entry to journal Will open your configured text editor on OS X if you didn't update the journal the previous day. This will allow you to add missing entries in bulk. It reads the settings in from the config YAML file and changes the date updated. It does the same with the journal file, reading in the YAML and merging the hash of entries, and then saves the YAML back again. There's also a method to check off a corresponding task in OmniFocus at the end.

Parameters:

  • entry (String)

    entry to add to the journal



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nikki.rb', line 28

def new(*args)
  settings = read_config
  settings[:updated] = today
  entry = args.join(" ")
  entry_hash = { today => entry }
  journal = read_file.merge(entry_hash)
  write_file(journal)
  open unless updated_yesterday?
  write_config(settings)
  add_to_omnifocus
  puts latest
end

- (Object) open

Open Nikki journal in configured text editor



44
45
46
47
48
49
50
# File 'lib/nikki.rb', line 44

def open
  if options[:marked]
    %x{open -a Marked #{file}}
  else
    %x{open -a "#{editor}" #{file}}
  end
end

- (Object) setup

This methods creates the “.nikki” directory, config file and journal file.



14
15
16
17
18
# File 'lib/nikki.rb', line 14

def setup
  create_path
  create_file
  create_config_file
end