Class: Generator
- Inherits:
-
Thor
- Object
- Thor
- Generator
- 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.
Instance Method Summary (collapse)
-
- (Object) config
Configure Nikki's settings.
-
- (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.
-
- (Object) open
Open Nikki journal in configured text editor.
-
- (Object) setup
This methods creates the “.nikki” directory, config file and journal file.
Instance Method Details
- (Object) config
Configure Nikki's settings
64 65 66 67 68 69 70 71 72 |
# File 'lib/nikki.rb', line 64 def config settings = read_config settings[:editor] = [:editor] || read_config[:editor] settings[:updated] = Date.today-1 if [:yesterday] settings[:updated] = Date.today if [:today] write_config(settings) puts settings.to_yaml if [:print] puts latest if [: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.
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 [: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 |