evertils 2.2.1 → 2.2.2

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: 7c46a2159d62b6e856e8dff4c06524f6e34098b556a6fa2db6732c3b90158e9c
4
- data.tar.gz: c33e3ee54a15c187f95e82a759c428bd5452e6ccf68e967b86d2760015e44a19
3
+ metadata.gz: 68a35d3e301fe99661e1de9a629f967c806aada550e5b56ad779edce73705086
4
+ data.tar.gz: c43e863a87f630189d7589906b0bbdb9f8e7bf2c0f7dc0d78da77678abbe866c
5
5
  SHA512:
6
- metadata.gz: 2ab525b278952924e836d3c10cacb497ef8a2ded543c0e3e839f559119c42dad49c7959442c728ed976c5bab56561e84d470c65e60d10755f5e135df2440d26d
7
- data.tar.gz: 6d7b58fdbfd3827d83820ec6a790a07f1967a161e4e3ffee496157bd13414c1ad5f50c8b236c41789a12dc113bcca8a106177d72e2b23fc5b00deedc00797600
6
+ metadata.gz: 700050701d54012695a4ecea2506a56fc16a4f52f07c93c14ef08e3aa873be813713a24496f9b3e2b05cb4df780e4e4e73bf8e2c3cb134fc250653ebd9997139
7
+ data.tar.gz: 6a196a2186d41d3525d8a3aaf13fe5517096772f38166f0522446444468b1835b56610a534914f5990ab2c82733a706760c7760e75ccb52b3f5eb6117c5c56a3
data/README.md CHANGED
@@ -18,7 +18,7 @@ See [this document](https://github.com/aapis/evertils/wiki/Logging-Specification
18
18
  |Command|Description|Usage|
19
19
  |:--------------|:-----------|:-------------|
20
20
  |generate|Create notes from templates|`evertils generate daily`, `evertils generate morning`, `evertils generate monthly`|
21
- |log|Write a line to a note|`evertils log message "I am a message"`|
21
+ |log|Interact with a note's content|`evertils log message "I am a message"`, `evertils log grep 2223`, `evertils log group`|
22
22
 
23
23
  ## Automation
24
24
 
@@ -6,15 +6,16 @@ module Evertils
6
6
 
7
7
  def execute
8
8
  case params.action
9
- when nil
10
- Notify.info 'Action not provided, creating new note...'
11
- Action::Create.new(params)
12
9
  when 'create'
13
10
  Action::Create.new(params)
14
11
  when 'create_multiple'
15
12
  Action::CreateMultiple.new(params.notes)
16
13
  when 'duplicate_previous'
17
14
  Action::DuplicatePrevious.new(params)
15
+ when 'search'
16
+ Action::Search.new(params)
17
+ when 'group'
18
+ Action::Group.new(params)
18
19
  else
19
20
  Action::Default.new(action: action)
20
21
  end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evertils
4
+ module Action
5
+ class Group < Action::Base
6
+ Formatting = Evertils::Helper::Formatting
7
+
8
+ #
9
+ # @since 2.2.2
10
+ def initialize(args)
11
+ @note_helper = Evertils::Helper::Note.instance
12
+ @args = args
13
+ @note = @note_helper.find_note_by_grammar(grammar.to_s)
14
+ @api_helper = Evertils::Helper::ApiEnmlHandler.new(@config)
15
+
16
+ execute
17
+ end
18
+
19
+ private
20
+
21
+ #
22
+ # @since 2.2.2
23
+ def execute
24
+ return Notify.error('Note not found') if @note.entity.nil?
25
+
26
+ group_by
27
+ end
28
+
29
+ #
30
+ # @since 2.2.2
31
+ def grammar
32
+ terms = Grammar.new
33
+ terms.tags = {
34
+ day: Date.today.yday,
35
+ week: Date.today.cweek
36
+ }
37
+ terms.notebook = @args.notebook
38
+ terms.created = Date.new(Date.today.year, 1, 1).strftime('%Y%m%d')
39
+ terms
40
+ end
41
+
42
+ #
43
+ # @since 2.2.2
44
+ def group_by
45
+ grouped_results.each_pair do |job_id, rows|
46
+ Notify.note("#{Formatting.clean(job_id)} - #{rows.size} occurrences") unless job_id.nil?
47
+
48
+ rows.each { |row| Notify.info(Formatting.clean(row)) }
49
+ end
50
+ end
51
+
52
+ #
53
+ # @since 2.2.2
54
+ def search_nodes
55
+ xml = @api_helper.from_str(@note.entity.content)
56
+ target = xml.search('en-note').first
57
+ nodes = []
58
+
59
+ target.children.each do |child|
60
+ node = child.children.first.to_s
61
+ nodes.push(Formatting.clean(node)) unless node.empty? || node == '<br/>'
62
+ end
63
+
64
+ nodes
65
+ end
66
+
67
+ #
68
+ # @since 2.2.2
69
+ def grouped_results
70
+ search_nodes.group_by do |node|
71
+ match = /- (.*)? -/.match(node)
72
+ match[1] unless match.nil?
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evertils
4
+ module Action
5
+ class Search < Action::Base
6
+ Formatting = Evertils::Helper::Formatting
7
+
8
+ #
9
+ # @since 2.2.2
10
+ def initialize(args)
11
+ @note_helper = Evertils::Helper::Note.instance
12
+ @args = args
13
+ @note = @note_helper.find_note_by_grammar(grammar.to_s)
14
+ @api_helper = Evertils::Helper::ApiEnmlHandler.new(@config)
15
+
16
+ execute
17
+ end
18
+
19
+ private
20
+
21
+ #
22
+ # @since 2.2.2
23
+ def execute
24
+ return Notify.error('Note not found') if @note.entity.nil?
25
+
26
+ search_for(@args.term)
27
+ end
28
+
29
+ #
30
+ # @since 2.2.2
31
+ def grammar
32
+ terms = Grammar.new
33
+ terms.tags = {
34
+ day: Date.today.yday,
35
+ week: Date.today.cweek
36
+ }
37
+ terms.notebook = @args.notebook
38
+ terms.created = Date.new(Date.today.year, 1, 1).strftime('%Y%m%d')
39
+ terms
40
+ end
41
+
42
+ #
43
+ # @since 2.2.2
44
+ def search_for(text)
45
+ results = grep_results_for(text)
46
+
47
+ return Notify.error("No rows matched search query {#{text}}") if results.empty?
48
+
49
+ Notify.success("#{results.size} rows matched query {#{text}}")
50
+ results.each { |res| Notify.info(Formatting.clean(res)) }
51
+ end
52
+
53
+ #
54
+ # @since 2.2.2
55
+ def search_nodes
56
+ xml = @api_helper.from_str(@note.entity.content)
57
+ target = xml.search('en-note').first
58
+ nodes = []
59
+
60
+ target.children.each do |child|
61
+ node = child.children.first.to_s
62
+ nodes.push(Formatting.clean(node)) unless node.empty? || node == '<br/>'
63
+ end
64
+
65
+ nodes
66
+ end
67
+
68
+ #
69
+ # @since 2.2.2
70
+ def grep_results_for(text)
71
+ return search_nodes.select { |line| line.scan(text) } if text.is_a? Regexp
72
+
73
+ search_nodes.select { |line| line.include? text }
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,5 +1,7 @@
1
1
  module Evertils
2
2
  module Controller
3
+ Formatting = Evertils::Helper::Formatting
4
+
3
5
  class Log < Controller::Base
4
6
  WORDS_PER_LINE = 20
5
7
 
@@ -28,23 +30,21 @@ module Evertils
28
30
  #
29
31
  # @since 2.2.0
30
32
  def grep(text = nil)
31
- return Notify.error('A search term is required') if text.nil?
32
-
33
- @note = @note_helper.find_note_by_grammar(grammar.to_s)
33
+ params = OpenStruct.new(term: text, action: 'search', notebook: 'Daily')
34
34
 
35
- return Notify.error('Note not found') if @note.entity.nil?
36
-
37
- search_for(text)
35
+ runner = ActionRunner.new
36
+ runner.params = params
37
+ runner.execute
38
38
  end
39
39
 
40
40
  #
41
41
  # @since 2.2.0
42
- def group(text = nil)
43
- @note = @note_helper.find_note_by_grammar(grammar.to_s)
42
+ def group
43
+ params = OpenStruct.new(action: 'group', notebook: 'Daily')
44
44
 
45
- return Notify.error('Note not found') if @note.entity.nil?
46
-
47
- group_by
45
+ runner = ActionRunner.new
46
+ runner.params = params
47
+ runner.execute
48
48
  end
49
49
 
50
50
  private
@@ -71,7 +71,7 @@ module Evertils
71
71
 
72
72
  @note.entity.content = xml.to_s
73
73
 
74
- Notify.success("Item logged at #{current_time}") if @note.update
74
+ Notify.success("Item logged at #{Formatting.current_time}") if @note.update
75
75
  end
76
76
 
77
77
  #
@@ -81,72 +81,11 @@ module Evertils
81
81
  target = xml.search('en-note').first
82
82
 
83
83
  text.each do |line|
84
- target.add_child("<div>* #{current_time} - #{clean(line)}</div>")
84
+ target.add_child("<div>* #{Formatting.current_time} - #{Formatting.clean(line)}</div>")
85
85
  end
86
86
 
87
87
  xml
88
88
  end
89
-
90
- #
91
- # @since 2.2.0
92
- def search_for(text)
93
- results = grep_results_for(text)
94
-
95
- return Notify.error("No rows matched search query {#{text}}") if results.empty?
96
-
97
- Notify.success("#{results.size} rows matched query {#{text}}")
98
- results.each { |res| Notify.info(clean(res)) }
99
- end
100
-
101
- #
102
- # @since 2.2.0
103
- def group_by
104
- grouped_results.each_pair do |job_id, rows|
105
- Notify.note("#{clean(job_id)} - #{rows.size} occurrences") unless job_id.nil?
106
-
107
- rows.each { |row| Notify.info(clean(row)) }
108
- end
109
- end
110
-
111
- #
112
- # @since 2.2.0
113
- def search_nodes
114
- xml = @api_helper.from_str(@note.entity.content)
115
- target = xml.search('en-note').first
116
- nodes = []
117
-
118
- target.children.each do |child|
119
- node = child.children.first.to_s
120
- nodes.push(clean(node)) unless node.empty? || node == '<br/>'
121
- end
122
-
123
- nodes
124
- end
125
-
126
- #
127
- # @since 2.2.0
128
- def grouped_results
129
- search_nodes.group_by do |node|
130
- match = /- (.*)? -/.match(node)
131
- match[1] unless match.nil?
132
- end
133
- end
134
-
135
- #
136
- # @since 2.2.0
137
- def grep_results_for(text)
138
- search_nodes.select { |line| line.include? text }
139
- end
140
-
141
- #
142
- # @since 2.2.0
143
- def clean(text)
144
- text.delete("\n").gsub('&#xA0;', ' ')
145
- end
146
-
147
- def current_time
148
- Time.now.strftime('%I:%M')
149
- end
150
89
  end
151
90
  end
152
91
  end
@@ -33,6 +33,18 @@ module Evertils
33
33
  result
34
34
  }
35
35
  end
36
+
37
+ #
38
+ # @since 2.2.0
39
+ def self.clean(text)
40
+ text.delete("\n").gsub('&#xA0;', ' ')
41
+ end
42
+
43
+ #
44
+ # @since 2.2.1
45
+ def self.current_time
46
+ Time.now.strftime('%I:%M')
47
+ end
36
48
  end
37
49
  end
38
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Evertils
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.2'
5
5
  end
data/lib/evertils.rb CHANGED
@@ -21,10 +21,13 @@ require 'evertils/kernel'
21
21
  require 'evertils/version'
22
22
  require 'evertils/base'
23
23
  require 'evertils/type'
24
+ require 'evertils/helpers/formatting'
24
25
  require 'evertils/action'
25
26
  require 'evertils/action_runner'
26
27
  require 'evertils/actions/default'
27
28
  require 'evertils/actions/create'
29
+ require 'evertils/actions/search'
30
+ require 'evertils/actions/group'
28
31
  require 'evertils/actions/create_multiple'
29
32
  require 'evertils/actions/duplicate_previous'
30
33
  require 'evertils/helpers/results'
@@ -37,7 +40,6 @@ require 'evertils/request'
37
40
  require 'evertils/controller'
38
41
  require 'evertils/controllers/render'
39
42
  require 'evertils/router'
40
- require 'evertils/helpers/formatting'
41
43
  require 'evertils/helpers/evernote-enml'
42
44
  require 'evertils/helpers/note'
43
45
  require 'evertils/helpers/xml'
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: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -116,6 +116,8 @@ files:
116
116
  - lib/evertils/actions/create_multiple.rb
117
117
  - lib/evertils/actions/default.rb
118
118
  - lib/evertils/actions/duplicate_previous.rb
119
+ - lib/evertils/actions/group.rb
120
+ - lib/evertils/actions/search.rb
119
121
  - lib/evertils/base.rb
120
122
  - lib/evertils/config.rb
121
123
  - lib/evertils/controller.rb