journal-cli 1.0.33 → 1.0.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 856b44dbd3e830d25f7d94daf3b037997ea43719c7f27e07bc69c120845cfb8f
4
- data.tar.gz: a1add0cbc28ac3e9858d2797048949cffd91c531b7cd5c95935dc0df58506ae8
3
+ metadata.gz: 1f62f54f397dd0589f5ba2584df91129cef9ed40d83941d7c07bb82b8164392e
4
+ data.tar.gz: df3046ab0fc6ae4436f4b99ede207fd8bef86ac8e6ea3b56661e8c678351e3a2
5
5
  SHA512:
6
- metadata.gz: cac9aef1b319685ec641a69d6c2810851da2a1c50345346d69161c64a2f6dcfa0a180e9705d7e6ab6b1249dcf21c3868db078d313f0e72aba42ca81aac047ba3
7
- data.tar.gz: f09710cca11dbdae0f826164b3cc613e5399700d444e320a9501c5398439b95b7bc538550be8e49d89d61a531c9818752fb52e3a5fdbc06d73e4bae7ff7f266f
6
+ metadata.gz: 57a2347a3cf429821d26d3d99b7cc849bcd6225cb63cf74591dac549c6609d6ec1056a2e6659627d27aba13eddcb5a52175fb76ca9505c0782e933a0643c5a1d
7
+ data.tar.gz: 7549d15f6795599ea695f2cc99f8faa8b02176bdc1a5328565efa4777a93d3646b83face27b686aa39fb23ec1ca15975def359a879ed138704d0c0300d0f2ad6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ### 1.0.35
2
+
3
+ 2024-06-22 11:45
4
+
5
+ #### IMPROVED
6
+
7
+ - Display answers to prompt when filling out entry
8
+ - Launch Day One before trying to add entry. Day One's database frequently gets updated and the command line tool will throw an error if Day One hasn't been launched. So launch it hidden in the background, and then quit if it wasn't running to begin with. This will cause the database to update.
9
+ - Method documentation
10
+
11
+ ### 1.0.34
12
+
13
+ 2024-06-22 11:01
14
+
15
+ #### FIXED
16
+
17
+ - Force -W1 so prompts always show up
18
+
1
19
  ### 1.0.33
2
20
 
3
21
  2024-04-20 13:47
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- journal-cli (1.0.32)
4
+ journal-cli (1.0.35)
5
5
  chronic (~> 0.10, >= 0.10.2)
6
6
  tty-reader (~> 0.9, >= 0.9.0)
7
7
  tty-which (~> 0.5, >= 0.5.0)
data/bin/journal CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby -W1
2
2
 
3
3
  $LOAD_PATH.unshift File.join(__dir__, '..', 'lib')
4
4
  require 'journal-cli'
@@ -1,10 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ##
4
+ ## Array helpers
5
+ ##
3
6
  class ::Array
7
+ ##
8
+ ## Find the shortest element in an array of strings
9
+ ##
10
+ ## @return [String] shortest element
11
+ ##
4
12
  def shortest
5
13
  inject { |memo, word| (memo.length < word.length) ? memo : word }
6
14
  end
7
15
 
16
+ ##
17
+ ## Find the longest element in an array of strings
18
+ ##
19
+ ## @return [String] longest element
20
+ ##
8
21
  def longest
9
22
  inject { |memo, word| (memo.length > word.length) ? memo : word }
10
23
  end
@@ -3,6 +3,11 @@ module Journal
3
3
  class Checkin
4
4
  attr_reader :key, :date, :data, :config, :journal, :sections, :title, :output
5
5
 
6
+ ##
7
+ ## Initialize a new checkin using a configured journal
8
+ ##
9
+ ## @param journal [Journal] The journal
10
+ ##
6
11
  def initialize(journal)
7
12
  @key = journal
8
13
  @output = []
@@ -19,26 +24,51 @@ module Journal
19
24
  @title = @journal["title"].sub(/%M/, meridian)
20
25
  end
21
26
 
27
+ ##
28
+ ## Add a title (Markdown) to the output
29
+ ##
30
+ ## @param string [String] The string
31
+ ##
22
32
  def add_title(string)
23
33
  @output << "\n## #{string}\n" unless string.nil?
24
34
  end
25
35
 
36
+ ##
37
+ ## Add a question header (Markdown) to the output
38
+ ##
39
+ ## @param string [String] The string
40
+ ##
26
41
  def header(string)
27
42
  @output << "\n##### #{string}\n" unless string.nil?
28
43
  end
29
44
 
45
+ ##
46
+ ## Add a section header (Markdown) to the output
47
+ ##
48
+ ## @param string [String] The string
49
+ ##
30
50
  def section(string)
31
51
  @output << "\n###### #{string}\n" unless string.nil?
32
52
  end
33
53
 
54
+ ##
55
+ ## Add a newline to the output
56
+ ##
34
57
  def newline
35
58
  @output << "\n"
36
59
  end
37
60
 
61
+ ##
62
+ ## Add a horizontal rule (Markdown) to the output
63
+ ##
38
64
  def hr
39
65
  @output << "\n* * * * * *\n"
40
66
  end
41
67
 
68
+ ##
69
+ ## Finalize the checkin, saving data to JSON, Day One,
70
+ ## and Markdown as configured
71
+ ##
42
72
  def go
43
73
  @sections.each { |key, section| @data[key] = section }
44
74
 
@@ -57,11 +87,31 @@ module Journal
57
87
  end
58
88
  end
59
89
 
90
+ ##
91
+ ## Launch Day One and quit if it wasn't running
92
+ ##
93
+ def launch_day_one
94
+ # Launch Day One to ensure database is up-to-date
95
+ # test if Day One is open
96
+ running = !`ps ax | grep "/MacOS/Day One" | grep -v grep`.strip.empty?
97
+ # -g do not bring app to foreground
98
+ # -j launch hidden
99
+ `/usr/bin/open -gj -a "Day One"`
100
+ # quit if it wasn't running
101
+ `osascript -e 'tell app "Day One" to quit'` if !running
102
+ end
103
+
104
+ ##
105
+ ## Save journal entry to Day One using the command line tool
106
+ ##
60
107
  def save_day_one_entry
61
108
  unless TTY::Which.exist?("dayone2")
62
109
  Journal.notify("{br}Day One CLI not installed, no Day One entry created")
63
110
  return
64
111
  end
112
+
113
+ launch_day_one
114
+
65
115
  @date.localtime
66
116
  cmd = ["dayone2"]
67
117
  cmd << %(-j "#{@journal["journal"]}") if @journal.key?("journal")
@@ -71,6 +121,9 @@ module Journal
71
121
  Journal.notify("{bg}Entered one entry into Day One")
72
122
  end
73
123
 
124
+ ##
125
+ ## Save entry to an existing Markdown file
126
+ ##
74
127
  def save_single_markdown
75
128
  dir = if @journal.key?("entries_folder")
76
129
  File.join(File.expand_path(@journal["entries_folder"]), "entries")
@@ -93,6 +146,9 @@ module Journal
93
146
  Journal.notify "{bg}Added new entry to {bw}#{target}"
94
147
  end
95
148
 
149
+ ##
150
+ ## Save journal entry to daily Markdown file
151
+ ##
96
152
  def save_daily_markdown
97
153
  dir = if @journal.key?("entries_folder")
98
154
  File.join(File.expand_path(@journal["entries_folder"]), "entries")
@@ -114,6 +170,9 @@ module Journal
114
170
  Journal.notify "{bg}Saved daily Markdown to {bw}#{target}"
115
171
  end
116
172
 
173
+ ##
174
+ ## Save journal entry to an new individual Markdown file
175
+ ##
117
176
  def save_individual_markdown
118
177
  dir = if @journal.key?("entries_folder")
119
178
  File.join(File.expand_path(@journal["entries_folder"]), "entries")
@@ -10,6 +10,11 @@ module Journal
10
10
  super
11
11
  end
12
12
 
13
+ ##
14
+ ## Convert Data object to a hash
15
+ ##
16
+ ## @return [Hash] Data representation of the object.
17
+ ##
13
18
  def to_data
14
19
  output = {}
15
20
  @questions.each do |q|
@@ -33,20 +33,22 @@ module Journal
33
33
 
34
34
  return nil unless @condition && condition
35
35
 
36
- case @type
37
- when /^int/i
38
- read_number(integer: true)
39
- when /^(float|num)/i
40
- read_number
41
- when /^(text|string|line)/i
42
- read_line
43
- when /^(weather|forecast)/i
44
- Weather.new(Journal.config["weather_api"], Journal.config["zip"], Journal.config["temp_in"])
45
- when /^multi/i
46
- read_lines
47
- when /^(date|time)/i
48
- read_date
49
- end
36
+ res = case @type
37
+ when /^int/i
38
+ read_number(integer: true)
39
+ when /^(float|num)/i
40
+ read_number
41
+ when /^(text|string|line)/i
42
+ read_line
43
+ when /^(weather|forecast)/i
44
+ Weather.new(Journal.config["weather_api"], Journal.config["zip"], Journal.config["temp_in"])
45
+ when /^multi/i
46
+ read_lines
47
+ when /^(date|time)/i
48
+ read_date
49
+ end
50
+ Journal.notify("{dw}#{prompt}: {dy}#{res}{x}".x)
51
+ res
50
52
  end
51
53
 
52
54
  private
@@ -2,6 +2,12 @@
2
2
 
3
3
  # String helpers
4
4
  class ::String
5
+
6
+ ##
7
+ ## Parse and test a condition
8
+ ##
9
+ ## @return [Boolean] whether test passed
10
+ ##
5
11
  def parse_condition
6
12
  condition = dup
7
13
  time_rx = /(?<comp>[<>=]{1,2}|before|after) +(?<time>(?:noon|midnight|[0-9]+) *(?:am|pm)?)$/i
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Journal
4
- VERSION = '1.0.33'
4
+ VERSION = '1.0.35'
5
5
  end
@@ -4,6 +4,13 @@ module Journal
4
4
  class Weather
5
5
  attr_reader :data
6
6
 
7
+ ##
8
+ ## Initialize the weather object, contacting API and parsing out conditions and forecast
9
+ ##
10
+ ## @param api [String] The api key
11
+ ## @param zip [String] The zip code
12
+ ## @param temp_in [String] F or C
13
+ ##
7
14
  def initialize(api, zip, temp_in)
8
15
  Journal.date.localtime
9
16
  res = if Journal.date.strftime("%Y-%m-%d") == Time.now.strftime("%Y-%m-%d")
@@ -43,13 +50,13 @@ module Journal
43
50
 
44
51
  hours = forecast["hour"]
45
52
  temps = [
46
- {temp: hours[8][temp_key], condition: hours[8]["condition"]["text"]},
47
- {temp: hours[10][temp_key], condition: hours[10]["condition"]["text"]},
48
- {temp: hours[12][temp_key], condition: hours[12]["condition"]["text"]},
49
- {temp: hours[14][temp_key], condition: hours[14]["condition"]["text"]},
50
- {temp: hours[16][temp_key], condition: hours[16]["condition"]["text"]},
51
- {temp: hours[18][temp_key], condition: hours[18]["condition"]["text"]},
52
- {temp: hours[19][temp_key], condition: hours[20]["condition"]["text"]}
53
+ { temp: hours[8][temp_key], condition: hours[8]["condition"]["text"] },
54
+ { temp: hours[10][temp_key], condition: hours[10]["condition"]["text"] },
55
+ { temp: hours[12][temp_key], condition: hours[12]["condition"]["text"] },
56
+ { temp: hours[14][temp_key], condition: hours[14]["condition"]["text"] },
57
+ { temp: hours[16][temp_key], condition: hours[16]["condition"]["text"] },
58
+ { temp: hours[18][temp_key], condition: hours[18]["condition"]["text"] },
59
+ { temp: hours[19][temp_key], condition: hours[20]["condition"]["text"] }
53
60
  ]
54
61
 
55
62
  @data = {
@@ -64,6 +71,11 @@ module Journal
64
71
  }
65
72
  end
66
73
 
74
+ ##
75
+ ## Convert weather object to hash
76
+ ##
77
+ ## @return [Hash] Data representation of the object.
78
+ ##
67
79
  def to_data
68
80
  {
69
81
  high: @data[:high],
@@ -73,22 +85,52 @@ module Journal
73
85
  }
74
86
  end
75
87
 
88
+ ##
89
+ ## Get moon phase
90
+ ##
91
+ ## @return [String] moon phase
92
+ ##
76
93
  def moon
77
94
  @data[:moon_phase]
78
95
  end
79
96
 
97
+ ##
98
+ ## Get current conditon
99
+ ##
100
+ ## @return [String] condition as string (54 and
101
+ ## Sunny)
102
+ ##
80
103
  def current
81
104
  "#{@data[:temp]} and #{@data[:current_condition]}"
82
105
  end
83
106
 
107
+ ##
108
+ ## Get daily forecast
109
+ ##
110
+ ## @return [String] daily forecast as string (Sunny
111
+ ## 65/80)
112
+ ##
84
113
  def forecast
85
114
  "#{@data[:condition]} #{@data[:high]}/#{@data[:low]}"
86
115
  end
87
116
 
117
+ ##
118
+ ## Weather condition and forecast
119
+ ##
120
+ ## @return [String] string representation of the
121
+ ## weather object.
122
+ ##
88
123
  def to_s
89
124
  "#{@data[:temp].round} and #{@data[:current_condition]} (#{@data[:high].round}/#{@data[:low].round})"
90
125
  end
91
126
 
127
+ ##
128
+ ## Markdown representation of data, including hourly
129
+ ## forecast and conditions
130
+ ##
131
+ ## @return [String] Markdown representation of the
132
+ ## weather object.
133
+ ##
92
134
  def to_markdown
93
135
  output = []
94
136
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journal-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.33
4
+ version: 1.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-20 00:00:00.000000000 Z
11
+ date: 2024-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-which
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  - !ruby/object:Gem::Version
270
270
  version: '0'
271
271
  requirements: []
272
- rubygems_version: 3.4.0.dev
272
+ rubygems_version: 3.5.11
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: journal