nikki 0.5.7 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dddfb4c9074d96caa42c2eaeaa2d3ff6751865d
4
- data.tar.gz: ee874e4d063a1154fa9d3da67c6a07e9add48a32
3
+ metadata.gz: df96721c6f7e903e772be3b0bcb13e0d350d2d7c
4
+ data.tar.gz: 0f2cd93c62189cc99dd68c17840b9d7d7c77f50e
5
5
  SHA512:
6
- metadata.gz: 9a342012f40e2f2943b188c22a2f86bd6cc64288ca2e31f2a29f65e5ad82ff400c95dc88ae0f09b11d62795b9a7c3cfbdd3547d4101bac48d67b450870798396
7
- data.tar.gz: 0c319bd24ee8f75e0bd92f20ccde68e7f79d10c9806a7c63b2d82274ef43602d4c43869cd5f4b7a17b414f758ed0d9d547d8e927144b6cdbb0fa400ff8902efa
6
+ metadata.gz: 28c5cb7d185cf27818f601becdfca46929f60a1759e8c1eea89aa888614244fcf02b238a9e6ff559d0f02753b061b9619060ff5c66cce74d8668dad318b1775f
7
+ data.tar.gz: fe47682a4916ed1983e81f68c9f520473bb4b0d116da1561165d2cd7e8dbc248df41d63d342e3cf5f007a68bf3aba7b056eab5cecc9356d542b18fcbb0f0f3e2
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/lib/nikki/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Sets version for RubyGems
2
2
  module Nikki
3
3
  # Sets version for RubyGems
4
- VERSION = '0.5.7'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/nikki.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'thor'
2
2
  require 'pathname'
3
- require 'yaml'
3
+ require 'yaml/store'
4
4
  require 'date'
5
5
  require 'fileutils'
6
6
 
@@ -8,16 +8,8 @@ require 'fileutils'
8
8
  # This is the main class that interfaces with Thor's methods and does all the
9
9
  # heavy lifting for Nikki. It's a bit of a "God" object. Sorries.
10
10
  class Generator < Thor
11
- # @!group Initial Setup
12
- desc 'setup', 'Creates new Nikki and config files.'
13
- # This methods creates the ".nikki" directory, config file and journal file.
14
- def setup
15
- create_path
16
- create_file
17
- create_config_file
18
- end
19
-
20
- # @!endgroup
11
+ NIKKI_PATH = Pathname.new("#{ENV['HOME']}/.nikki")
12
+ NIKKI_FILE = Pathname.new("#{ENV['HOME']}/.nikki/nikki.yaml")
21
13
 
22
14
  # @!group Data entry
23
15
  desc 'new ENTRY', 'Creates a new entry in the Nikki journal.'
@@ -30,21 +22,12 @@ class Generator < Thor
30
22
  # Reads the settings in from the config YAML file and changes the
31
23
  # date updated. It does the same with the journal file, reading in the YAML
32
24
  # and merging the hash of entries, and then saves the YAML back again.
33
- def new(entry, update=nil)
34
- settings = read_config
35
- if update
36
- date = Date.parse(update)
37
- settings[:updated] = date
38
- else
39
- date = today
40
- settings[:updated] = today
25
+ def new(entry, date = Date.today)
26
+ YAML::Store.new("#{ENV['HOME']}/.nikki/nikki.yaml").transaction do |store|
27
+ store['entries'] << { date => entry.strip }
41
28
  end
42
- entry_hash = { date => "\"#{entry}\""}
43
- journal = read_file.merge(entry_hash)
44
- write_file(journal)
45
- open unless updated_yesterday?
46
- write_config(settings)
47
- puts latest
29
+
30
+ ls
48
31
  end
49
32
 
50
33
  desc 'missed', 'Create new entry for yesterday'
@@ -52,14 +35,14 @@ class Generator < Thor
52
35
  # @param entry [String]
53
36
  # @since 0.5.3
54
37
  def missed(entry)
55
- new(entry, (Date.today - 1).to_s)
38
+ new(entry, (Date.today - 1))
56
39
  end
57
40
  # @!endgroup
58
41
 
59
42
  desc 'open', "Open current year's journal file in editor."
60
43
  # Open Nikki journal in configured text editor
61
44
  def open
62
- system(ENV['EDITOR'], file.to_s)
45
+ system(ENV['EDITOR'], NIKKI_FILE.to_s)
63
46
  end
64
47
 
65
48
  desc 'ls', 'Displays latest Nikki entries.'
@@ -67,137 +50,22 @@ class Generator < Thor
67
50
  # @return [String]
68
51
  # @option options :sticky [String]
69
52
  def ls
70
- puts latest
71
- end
72
-
73
- desc 'config', "Change Nikki's settings."
74
- option :editor, :aliases => :e, :banner => "Set default editor to open journal file in."
75
- option :yesterday, :aliases => :y, :type => :boolean, :banner => "Set nikki's \"updated\" date to yesterday."
76
- option :today, :aliases => :t, :type => :boolean, :banner => "Set nikki's \"updated\" date to today."
77
- option :print, :aliases => :p, :type => :boolean, :banner => "Prints nikki's config settings."
78
- option :latest, :aliases => :l, :type => :boolean, :banner => "Prints latest journal entries."
79
- # Configure Nikki's settings
80
- # @param [Hash] options The options for configuring Nikki
81
- # @option options :editor [String] (read_config[:editor]) Sets Nikki's editor to open journal file
82
- # @option options :yesterday [Boolean] Set `settings[:updated]` to yesterday
83
- # @option options :today [Boolean] Set `settings[:updated]` to today
84
- # @option options :print [Boolean] Prints Nikki's configuration settings to STDOUT
85
- # @option options :latest [Boolean] Prints Nikki's latest entries to STDOUT
86
- def config
87
- settings = read_config
88
- settings[:editor] = options[:editor] || read_config[:editor]
89
- settings[:updated] = options[:yesterday] ? Date.today - 1 : Date.today
90
- write_config(settings)
91
- puts settings.to_yaml if options[:print]
92
- puts latest if options[:latest]
93
- end
94
-
95
- desc 'export YEAR', 'Export Nikki journal from YEAR as YAML'
96
- # @param [String] year of journal entries you wish to export
97
- def export(year)
98
- export_path = "#{path}nikki_export_#{year}.yml"
99
- IO.write(export_path, yamlize(read_file, year.to_i))
100
- puts "YAML saved to \"#{export_path}\"."
101
- end
102
-
103
- no_commands do
104
- def path
105
- Pathname.new("#{ENV['HOME']}/.nikki/")
106
- end
107
-
108
- def create_path
109
- path.mkdir unless path.exist?
110
- end
111
-
112
- def config_file
113
- path.join('nikki.config.yaml')
114
- end
115
-
116
- def read_config
117
- create_path
118
- config_file_exist?
119
- YAML.load(config_file.read)
120
- end
121
-
122
- def write_config(hash)
123
- config_file.open('w') { |t| t << hash.to_yaml }
124
- end
125
-
126
- def read_file
127
- create_path
128
- file_exist?
129
- YAML.load(file.read)
130
- end
131
-
132
- def write_file(hash)
133
- file.write(hash.to_yaml)
134
- end
135
-
136
- def editor
137
- read_config[:editor]
138
- end
139
-
140
- def file
141
- path.join('nikki.yaml')
142
- end
143
-
144
- def config_file_exist?
145
- return true if config_file.exist?
146
- create_config_file
147
- true
148
- end
149
-
150
- def file_exist?
151
- return true if file.exist?
152
- create_file
153
- true
154
- end
155
-
156
- def create_config_file
157
- settings = {}
158
- settings[:updated] = today
159
- settings[:editor] = 'TextEdit'
160
- write_config(settings)
161
- end
162
-
163
- def create_file
164
- FileUtils.touch(file)
165
- end
166
-
167
- def today
168
- Date.today
169
- end
170
-
171
- def yesterday
172
- Date.today - 1
173
- end
174
-
175
- def leap_year?
176
- Date.today.leap?
177
- end
178
-
179
- def last_updated
180
- read_config[:updated]
181
- end
182
-
183
- def updated_yesterday?
184
- last_updated == Date.today - 1
185
- end
186
-
187
- def latest
188
- list = []
189
- (0..3).each do |n|
190
- list << "#{today - n}: #{read_file[today - n]}"
191
- end
192
- list.reverse!
193
- end
194
-
195
- def yamlize(hash, year)
196
- string = "---\n"
197
- hash.each_pair do |date, sentence|
198
- string += "#{date}: \"#{sentence}\"\n" if date.year == year
53
+ YAML::Store.new(NIKKI_FILE).transaction do |store|
54
+ entries = store['entries'].last(5)
55
+ entries.each do |entry|
56
+ entry.each do |date, text|
57
+ puts "#{date.to_s}: #{text}"
58
+ end
199
59
  end
200
- string
201
60
  end
202
61
  end
62
+
63
+ # desc 'export YEAR', 'Export Nikki journal from YEAR as YAML'
64
+ # @param [String] year of journal entries you wish to export
65
+ # def export(year)
66
+ # TODO Fix this export command
67
+ # export_path = "#{NIKKI_PATH}/nikki_export_#{year}.yml"
68
+ # IO.write(export_path, yamlize(read_file, year.to_i))
69
+ # puts "YAML saved to \"#{export_path}\"."
70
+ # end
203
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nikki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Pittman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -76,8 +76,8 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".rspec"
79
+ - ".ruby-version"
79
80
  - ".tags"
80
- - ".travis.yml"
81
81
  - Gemfile
82
82
  - License.txt
83
83
  - README.md
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.5.1
117
+ rubygems_version: 2.5.2
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: A simple one-line-a-day journaling app.
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.1