class Generator
@author Brandon Pittman 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.
Constants
- NIKKI_FILE
Public Instance Methods
@param [String] year of journal entries you wish to export
# File lib/nikki.rb, line 65 def export(export_year) YAML::Store.new(NIKKI_FILE).transaction do |store| store['entries'].each do |entry| if entry.keys[0].year.to_s == export_year puts "#{entry.keys[0]}: #{entry.values[0]}" end end end end
Display Nikki’s latest entires @return [String] @option options :sticky [String]
# File lib/nikki.rb, line 52 def ls YAML::Store.new(NIKKI_FILE).transaction do |store| entries = store['entries'].last(5) entries.each do |entry| entry.each do |date, text| puts "#{date}: #{text}" end end end end
Creates a new entry for yesterday @param entry [String] @since 0.5.3
# File lib/nikki.rb, line 37 def missed(entry) new(entry, (Date.today - 1)) end
Add entry to journal @param entry [String] entry to add to the journal @param update [String] International date for update @return [Hash] Returns a Hash which is then saved in a YAML file. @example
"nikki new 'This is a thing I learned today!'"
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.
# File lib/nikki.rb, line 25 def new(entry, date = Date.today) YAML::Store.new("#{ENV['HOME']}/.nikki/nikki.yaml").transaction do |store| store['entries'] << { date => entry.strip } end ls end
Open Nikki
journal in configured text editor
# File lib/nikki.rb, line 44 def open system(ENV['EDITOR'], NIKKI_FILE) end