evertils 1.0.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: '090e7c596124e90b0ef20118f78f1609906eac814fc70f5c68b8c10f8509d867'
4
- data.tar.gz: fdeda657569494c3fba6a650820f15dae663be3624d7f6650549bc3e240f4847
3
+ metadata.gz: da72e4388eada49ffce7a77efb8cc712c4a97ecd153561ac37e42111af92c6b1
4
+ data.tar.gz: e8835575faee6e0ffa12d7a9a8ba39865722181ac9038c14900b446f383ef2d9
5
5
  SHA512:
6
- metadata.gz: 0c98eedc392dfac24e4e23f28a59cbac12667df4aeb250c4db768bc0ad19890446788329021a19fdb2578ed26338076b0c7f1a3d8caff0aeebde3189dbf7baa5
7
- data.tar.gz: 12dea2af67a4415d7deaa52d7ccb23e6b96ea0cb047100a4fec638cdf76c11c0a57e9278fa3c47ca0e91e83e99c5cc2275531d393c56bbd3443cb5b8925271d9
6
+ metadata.gz: 6c578630beddc02d38369f2f2c81b2b388ca807eb6be62174e4843742d9c0c01bcc116ff8cdb0a0e902615d3142959f5886033245913430757ede602d4308066
7
+ data.tar.gz: 03fc086116fa06f436b109d8e2c3845c867c8683ffc8ea0e9841ea523dcebdde1b2de59a574d3044c2492b346a6ef0c28260320e206248fe63ab015d83e0cd9b
@@ -1,5 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Evertils
2
4
  class Cfg
5
+ REPLACEMENTS = {
6
+ '%DOY%': Date.today.yday,
7
+ '%MONTH_NAME%': Date.today.strftime('%B'),
8
+ '%MONTH%': Date.today.month,
9
+ '%DAY%': Date.today.day,
10
+ '%DOW%': Date.today.wday,
11
+ '%DOW_NAME%': Date.today.strftime('%a'),
12
+ '%YEAR%': Date.today.year,
13
+ '%WEEK%': Date.today.cweek,
14
+ '%WEEK_START%': Date.commercial(Date.today.year, Date.today.cweek, 1),
15
+ '%WEEK_END%': Date.commercial(Date.today.year, Date.today.cweek, 5)
16
+ }
3
17
 
4
18
  # default values for initialization
5
19
  def initialize
@@ -66,11 +80,40 @@ module Evertils
66
80
  end
67
81
 
68
82
  def symbolize!
69
- @yml = @yml.inject({}) { |h, (k, v)| h[k.to_sym] = v; h}
83
+ @yml = @yml.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
70
84
  end
71
85
 
72
86
  def pluck(*args)
73
- @yml.slice(*args)
87
+ @yml.select do |key, _|
88
+ args.include? key
89
+ end
90
+ end
91
+
92
+ def translate_placeholders
93
+ @yml.map do |item|
94
+ REPLACEMENTS.each_pair do |k, v|
95
+ item.last.gsub!(k.to_s, v.to_s) if item.last.is_a? String
96
+ item.last.map { |i| i.gsub!(k.to_s, v.to_s) } if item.last.is_a? Array
97
+ end
98
+ end
99
+
100
+ symbolize_keys(@yml)
101
+ self
102
+ end
103
+
104
+ def symbolize_keys(hash)
105
+ hash.inject({}){ |result, (key, value)|
106
+ new_key = case key
107
+ when String then key.to_sym
108
+ else key
109
+ end
110
+ new_value = case value
111
+ when Hash then symbolize_keys(value)
112
+ else value
113
+ end
114
+ result[new_key] = new_value
115
+ result
116
+ }
74
117
  end
75
118
 
76
119
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Evertils
2
4
  module Controller
3
5
  class Base
@@ -58,7 +60,7 @@ module Evertils
58
60
  @method = command
59
61
  elsif is_a? Evertils::Controller::Render
60
62
  @method = :from_file
61
- @request.param = config.pluck(:path, :notebook)
63
+ @request.param = config
62
64
  else
63
65
  raise NoMethodError, "Invalid method: #{command}"
64
66
  end
@@ -12,7 +12,7 @@ module Evertils
12
12
  def message(text = nil)
13
13
  return Notify.error('A message is required', {}) if text.nil?
14
14
 
15
- note = @note_helper.wait_for(:Daily)
15
+ note = @note_helper.wait_for_by_notebook(:Daily)
16
16
  edit_conf = {
17
17
  search: 'Triage',
18
18
  append: text
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'evertils/common/query/simple'
2
4
 
3
5
  module Evertils
4
6
  module Controller
5
7
  class Render < Controller::Base
6
8
  def from_file(config)
7
- @config = config
9
+ @config = config.translate_placeholders.pluck(:title, :notebook)
10
+
8
11
  return Notify.warning("Note already exists\n- #{@link}") if note_exists?
9
12
 
10
13
  Notify.info 'Note not found, creating a new one'
@@ -15,7 +18,7 @@ module Evertils
15
18
 
16
19
  def note_exists?
17
20
  helper = Evertils::Helper.load('Note')
18
- note = helper.wait_for(@config[:notebook].to_sym, 3)
21
+ note = helper.wait_for_by_title(@config[:title], @config[:notebook], 3)
19
22
  @link = helper.external_url_for(note.entity) unless note.entity.nil?
20
23
 
21
24
  note.exists?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Evertils
2
4
  module Helper
3
5
  class Formatting
@@ -12,16 +12,16 @@ module Evertils
12
12
  end
13
13
 
14
14
  # Wait for a note to exist
15
- def wait_for(notebook, iterations = Evertils::Type::Base::MAX_SEARCH_SIZE)
15
+ def wait_for_by_notebook(notebook, iterations = Evertils::Type::Base::MAX_SEARCH_SIZE)
16
16
  Notify.info("Waiting for #{notebook}...")
17
- note = find_note(notebook)
17
+ note = find_note_by_notebook(notebook)
18
18
 
19
19
  begin
20
20
  # didn't find it the first time? wait and try again
21
21
  if note.entity.nil?
22
22
  (1..iterations).each do |iter|
23
23
  Notify.info(" (#{iter}) Looking for #{notebook.downcase}")
24
- note = find_note(notebook, true)
24
+ note = find_note_by_notebook(notebook, true)
25
25
  break unless note.entity.nil? || iter == Evertils::Type::Base::MAX_SEARCH_SIZE
26
26
  end
27
27
  end
@@ -32,13 +32,41 @@ module Evertils
32
32
  note
33
33
  end
34
34
 
35
- # Find a note
36
- def find_note(notebook, sleep = false)
35
+ # Wait for a note to exist
36
+ def wait_for_by_title(title, notebook, iterations = Evertils::Type::Base::MAX_SEARCH_SIZE)
37
+ Notify.info("Waiting for #{notebook}...")
38
+ note = find_note_by_title(title)
39
+
40
+ begin
41
+ # didn't find it the first time? wait and try again
42
+ if note.entity.nil?
43
+ (1..iterations).each do |iter|
44
+ Notify.info(" (#{iter}) Looking for #{notebook.downcase}")
45
+ note = find_note_by_title(notebook, true)
46
+ break unless note.entity.nil? || iter == Evertils::Type::Base::MAX_SEARCH_SIZE
47
+ end
48
+ end
49
+ rescue Interrupt
50
+ Notify.warning('Cancelled wait')
51
+ end
52
+
53
+ note
54
+ end
55
+
56
+ # Find a note by note
57
+ def find_note_by_title(title, sleep = false)
58
+ sleep(5) if sleep
59
+ @model.find_note_contents(title)
60
+ end
61
+
62
+ # Find a note by notebook
63
+ def find_note_by_notebook(notebook, sleep = false)
37
64
  sleep(5) if sleep
38
65
  title = @format.date_templates[notebook]
66
+
39
67
  @model.find_note_contents(title)
40
68
  end
41
- alias find_by_notebook find_note
69
+ # alias find_by_notebook
42
70
 
43
71
  #
44
72
  # @since 0.3.15
@@ -32,7 +32,7 @@ module Evertils
32
32
  # @since 0.3.13
33
33
  def attach_pq_note
34
34
  enml = @api.from_str(@format.template_contents(NOTEBOOK))
35
- pq = @note_helper.wait_for(:'Priority Queue')
35
+ pq = @note_helper.wait_for_by_notebook(:'Priority Queue')
36
36
  xml_conf = {
37
37
  href: @note_helper.internal_url_for(pq.entity),
38
38
  content: @format.date_templates[:'Priority Queue']
@@ -22,7 +22,7 @@ module Evertils
22
22
  #
23
23
  # @since 0.3.15
24
24
  def add_weekly_note_link
25
- wk_entity = @note_helper.wait_for(:Weekly).entity
25
+ wk_entity = @note_helper.wait_for_by_notebook(:Weekly).entity
26
26
  # parse the ENML note data into something we can work with
27
27
  xml = @api.from_str(@entity.content)
28
28
  # include the XML element builder
@@ -25,7 +25,7 @@ module Evertils
25
25
  #
26
26
  # @since 0.3.15
27
27
  def add_daily_note_link
28
- da_entity = @note_helper.wait_for(:Daily).entity
28
+ da_entity = @note_helper.wait_for_by_notebook(:Daily).entity
29
29
  # parse the ENML note data into something we can work with
30
30
  xml = @api.from_str(@entity.content)
31
31
  # include the XML element builder
@@ -1,3 +1,3 @@
1
1
  module Evertils
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evertils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe