journal-cli 1.0.34 → 1.0.36

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: 29a2bf23b86563b74a924d299a9abcced78ee4ea461dbbd537e49682ccbe0d75
4
- data.tar.gz: 9790b487cce722f84c8b8e052d3cc558a84684ea37df3b33091b80f871b5a9b6
3
+ metadata.gz: 1db983c29a889c30481070cdc131691b66b787ef29a8095499af105f5e4997a4
4
+ data.tar.gz: a44873884efad1c464a98789fd9ea067eeb16be407829b23585f8122d410c8aa
5
5
  SHA512:
6
- metadata.gz: e8f3ae5b2feec8f3083fdbe9842b8ca0dcb0790419b12b748157e36919125f0533108cc23abd5ae9cf7f1eaed1ca960c332a3f8acaa6c46262daf9bf1bd534f4
7
- data.tar.gz: 8bec17925e1c96320d31d6f71085d8e17996323c5d923fd3b71372096d28bbfda997b3699f909776f5c58729aa927741cb1e5ab2308e5a576a84b952b527605b
6
+ metadata.gz: fd42f6389075da4f2d2376ace587885a50359e00e025e26bcb5987e55c690aa75bd340c4e7c811b102d52ce0d176f4d8a84c3f850fdc4a7578acd5816f650164
7
+ data.tar.gz: a8656911b379f17fe0b738f04b5e40971ba3a504b2964eeee406abb353359537b57ee04bd4e63488907037612a09b61781c4986b2d539b6763dbe45b072b23d6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ### 1.0.36
2
+
3
+ 2024-07-03 11:31
4
+
5
+ #### FIXED
6
+
7
+ - Give Day One time to launch and update db when adding entry
8
+
9
+ ### 1.0.35
10
+
11
+ 2024-06-22 11:45
12
+
13
+ #### IMPROVED
14
+
15
+ - Display answers to prompt when filling out entry
16
+ - 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.
17
+ - Method documentation
18
+
1
19
  ### 1.0.34
2
20
 
3
21
  2024-06-22 11:01
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- journal-cli (1.0.34)
4
+ journal-cli (1.0.36)
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)
@@ -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,30 @@ 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
+ sleep 3
101
+ end
102
+
103
+ ##
104
+ ## Save journal entry to Day One using the command line tool
105
+ ##
60
106
  def save_day_one_entry
61
107
  unless TTY::Which.exist?("dayone2")
62
108
  Journal.notify("{br}Day One CLI not installed, no Day One entry created")
63
109
  return
64
110
  end
111
+
112
+ launch_day_one
113
+
65
114
  @date.localtime
66
115
  cmd = ["dayone2"]
67
116
  cmd << %(-j "#{@journal["journal"]}") if @journal.key?("journal")
@@ -69,8 +118,14 @@ module Journal
69
118
  cmd << %(-date "#{@date.strftime("%Y-%m-%d %I:%M %p")}")
70
119
  `echo #{Shellwords.escape(to_markdown(yaml: false, title: true))} | #{cmd.join(" ")} -- new`
71
120
  Journal.notify("{bg}Entered one entry into Day One")
121
+
122
+ # quit if it wasn't running
123
+ `osascript -e 'tell app "Day One" to quit'` if !@running
72
124
  end
73
125
 
126
+ ##
127
+ ## Save entry to an existing Markdown file
128
+ ##
74
129
  def save_single_markdown
75
130
  dir = if @journal.key?("entries_folder")
76
131
  File.join(File.expand_path(@journal["entries_folder"]), "entries")
@@ -93,6 +148,9 @@ module Journal
93
148
  Journal.notify "{bg}Added new entry to {bw}#{target}"
94
149
  end
95
150
 
151
+ ##
152
+ ## Save journal entry to daily Markdown file
153
+ ##
96
154
  def save_daily_markdown
97
155
  dir = if @journal.key?("entries_folder")
98
156
  File.join(File.expand_path(@journal["entries_folder"]), "entries")
@@ -114,6 +172,9 @@ module Journal
114
172
  Journal.notify "{bg}Saved daily Markdown to {bw}#{target}"
115
173
  end
116
174
 
175
+ ##
176
+ ## Save journal entry to an new individual Markdown file
177
+ ##
117
178
  def save_individual_markdown
118
179
  dir = if @journal.key?("entries_folder")
119
180
  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.34'
4
+ VERSION = '1.0.36'
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.34
4
+ version: 1.0.36
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-06-22 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-which