evertils 1.0.1 → 1.0.2

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: da72e4388eada49ffce7a77efb8cc712c4a97ecd153561ac37e42111af92c6b1
4
- data.tar.gz: e8835575faee6e0ffa12d7a9a8ba39865722181ac9038c14900b446f383ef2d9
3
+ metadata.gz: 4551493972d922f3eba9a4fb0c3c3d4a3bb8e1d37afbab5fcc4a1a478aa8f23c
4
+ data.tar.gz: 70cc8fc5284fcfaec3d205e21e05218174f6ab31553996742b7a726393c2fe04
5
5
  SHA512:
6
- metadata.gz: 6c578630beddc02d38369f2f2c81b2b388ca807eb6be62174e4843742d9c0c01bcc116ff8cdb0a0e902615d3142959f5886033245913430757ede602d4308066
7
- data.tar.gz: 03fc086116fa06f436b109d8e2c3845c867c8683ffc8ea0e9841ea523dcebdde1b2de59a574d3044c2492b346a6ef0c28260320e206248fe63ab015d83e0cd9b
6
+ metadata.gz: 5ee59f111daefc822ef9301cf9f3b7c294fe5f3124cd320c2922aa4c19816b7881974aca6f9f27417c23164fb8f9134a6934c6b83ab721cbcba384417ed23780
7
+ data.tar.gz: 4124c32c5626fe9da21c2d43e9d5677ea1b0ea0d3c2c48becb65cbfdd475abe4d1b5dff9ed9a8df1781ace405c0313099a1981379b9f4d0ff03f74b098835e78
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evertils
4
+ module Action
5
+ class Base
6
+ def initialize(args)
7
+ @args = args
8
+ @note_helper = Evertils::Helper.load('Note')
9
+ @api = Evertils::Helper.load('ApiEnmlHandler', {})
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'evertils/common/query/simple'
4
+
5
+ module Evertils
6
+ module Action
7
+ class Create < Action::Base
8
+ def initialize(args)
9
+ query = Evertils::Common::Query::Simple.new
10
+ query.create_note_from_yml(args[:path])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evertils
4
+ module Action
5
+ class DuplicatePrevious < Action::Base
6
+ def initialize(args)
7
+ super(args)
8
+
9
+ @args[:content] = find_previous(args)
10
+
11
+ query = Evertils::Common::Query::Simple.new
12
+ query.create_note_from_hash(@args)
13
+ end
14
+
15
+ private
16
+
17
+ def find_previous(args)
18
+ day = Date.today
19
+ note = nil
20
+
21
+ Notify.info("Searching for last #{@args[:notebook]}...")
22
+
23
+ (1..Evertils::Type::Base::MAX_SEARCH_SIZE).each do |iter|
24
+ day -= 1
25
+ dow = day.strftime('%a')
26
+
27
+ # always skip weekends, even if there is a note for those days
28
+ next if %i[Sat Sun].include?(dow)
29
+
30
+ note_title = @args[:title]
31
+ note = @note_helper.model.find_note_contents(note_title).entity
32
+
33
+ Notify.info(" (#{iter}) #{note_title}")
34
+
35
+ break unless note.nil?
36
+ end
37
+
38
+ @api.convert_to_xml(note.content).prepare
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,19 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'evertils/common/query/simple'
4
-
5
3
  module Evertils
6
4
  module Controller
7
5
  class Render < Controller::Base
8
6
  def from_file(config)
9
- @config = config.translate_placeholders.pluck(:title, :notebook)
7
+ @config = config.translate_placeholders.pluck(:title, :notebook, :path, :action)
10
8
 
11
9
  return Notify.warning("Note already exists\n- #{@link}") if note_exists?
12
10
 
13
11
  Notify.info 'Note not found, creating a new one'
14
12
 
15
- query = Evertils::Common::Query::Simple.new
16
- query.create_note_from_yml(@config[:path])
13
+ execute_action(@config[:action].to_sym || :create)
17
14
  end
18
15
 
19
16
  def note_exists?
@@ -23,6 +20,15 @@ module Evertils
23
20
 
24
21
  note.exists?
25
22
  end
23
+
24
+ def execute_action(action)
25
+ case action
26
+ when :duplicate_previous
27
+ Action::DuplicatePrevious.new(@config)
28
+ else
29
+ Action::Create.new(@config)
30
+ end
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module Evertils
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  end
data/lib/evertils.rb CHANGED
@@ -21,6 +21,9 @@ require 'evertils/kernel'
21
21
  require 'evertils/version'
22
22
  require 'evertils/base'
23
23
  require 'evertils/type'
24
+ require 'evertils/action'
25
+ require 'evertils/actions/create'
26
+ require 'evertils/actions/duplicate_previous'
24
27
  require 'evertils/helpers/time'
25
28
  require 'evertils/helpers/results'
26
29
  require 'evertils/helpers/api-enml-handler'
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -110,6 +110,9 @@ files:
110
110
  - com.evertils.plist.dist
111
111
  - evertils.gemspec
112
112
  - lib/evertils.rb
113
+ - lib/evertils/action.rb
114
+ - lib/evertils/actions/create.rb
115
+ - lib/evertils/actions/duplicate_previous.rb
113
116
  - lib/evertils/base.rb
114
117
  - lib/evertils/config.rb
115
118
  - lib/evertils/configs/templates/daily.enml