evertils-common 0.3.9 → 0.3.10

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
- SHA1:
3
- metadata.gz: 5370c3c9e5231a1b60d8cfb9a2a10d78a8ef0dc2
4
- data.tar.gz: 3ffce08e43c708fa4e6c75057c28025a4e514521
2
+ SHA256:
3
+ metadata.gz: 22dd994d7ac10f3862a2d5ebea103ea136864a3e8b9f58c4696a24df4c3fd6b3
4
+ data.tar.gz: 513b9d7f97fa5bea2796267734dc5ff759fc1d3c204a5f01d69c189998f5ddd9
5
5
  SHA512:
6
- metadata.gz: e073b9dacb1c9e4502f83233b3e7c2cc58a985acddba78ac1df77623433458ee2f036fdfc4d3ffde876d69babe79a82930a799603053818207199fe2d417f8e9
7
- data.tar.gz: bfa43f4f59dfb7ec21d0d89ca4367e0bb15ffa38142690e753613fdc12918d52c599d1c9d57d8c3534917e9c6c58fdaf15ba2385b7cd4c29dc9eef561dee9359
6
+ metadata.gz: 9f958b628108cba980269b5a9cfe58ed721523f6104045b2378eabe34a95b4b6fc190dde97e01d3b070565896342b93359acb718284432c763552d497d143a6c
7
+ data.tar.gz: 21b87e63f9412b83fcc12039bfe44e9f678d098e479ecbc2944dacd2efbbdbeacd657e2768270190c28489d07452bb6c7155454afdec15cf91bb61d7c1c61f64
@@ -4,12 +4,51 @@ module Evertils
4
4
  class Base < Common::Generic
5
5
  attr_accessor :entity
6
6
 
7
+ REPLACEMENTS = {
8
+ '%DOY%': Date.today.yday,
9
+ '%MONTH_NAME%': Date.today.strftime('%B'),
10
+ '%MONTH%': Date.today.month,
11
+ '%DAY%': Date.today.day,
12
+ '%DOW%': Date.today.wday,
13
+ '%DOW_NAME%': Date.today.strftime('%a'),
14
+ '%YEAR%': Date.today.year,
15
+ '%WEEK%': Date.today.cweek,
16
+ '%WEEK_START%': Date.commercial(Date.today.year, Date.today.cweek, 1),
17
+ '%WEEK_END%': Date.commercial(Date.today.year, Date.today.cweek, 5)
18
+ }
19
+
7
20
  def initialize
8
21
  @evernote = Authentication.instance
9
22
 
10
23
  super
11
24
  end
12
25
 
26
+ def placeholders_for(items)
27
+ items.map do |item|
28
+ REPLACEMENTS.each_pair do |k, v|
29
+ item.last.gsub!(k.to_s, v.to_s) if item.last.is_a? String
30
+ item.last.map { |i| i.gsub!(k.to_s, v.to_s) } if item.last.is_a? Array
31
+ end
32
+ end
33
+
34
+ symbolize_keys(items)
35
+ end
36
+
37
+ def symbolize_keys(hash)
38
+ hash.inject({}){ |result, (key, value)|
39
+ new_key = case key
40
+ when String then key.to_sym
41
+ else key
42
+ end
43
+ new_value = case value
44
+ when Hash then symbolize_keys(value)
45
+ else value
46
+ end
47
+ result[new_key] = new_value
48
+ result
49
+ }
50
+ end
51
+
13
52
  #
14
53
  # @since 0.2.8
15
54
  def start_of_day(date = ::Time.now)
@@ -8,16 +8,14 @@ module Evertils
8
8
  raise "File not found: #{full_path}" unless File.exist? full_path
9
9
 
10
10
  begin
11
- conf = YAML::load(File.open(full_path))
12
- required = %w(title body)
11
+ conf = placeholders_for(YAML.safe_load(File.read(full_path)))
12
+ required = %w[title sections]
13
13
 
14
- if has_required_fields(conf, required)
15
- create(conf['title'], conf['body'], conf['parent'])
16
- else
17
- raise ArgumentError, 'Configuration file is missing some required fields'
18
- end
14
+ return create(conf) if has_required_fields(conf, required) && !exists?
15
+
16
+ raise ArgumentError, 'Configuration file is missing some required fields'
19
17
  rescue ArgumentError => e
20
- puts e.message
18
+ Notify.error e.message
21
19
  end
22
20
  end
23
21
 
@@ -11,21 +11,26 @@ module Evertils
11
11
  # @since 0.3.3
12
12
  def initialize(conf = {})
13
13
  raise "Title (title) is a required field" unless conf[:title]
14
- raise "Body (body) is a required field" unless conf[:body]
14
+ raise "Body (body) is a required field" unless conf[:sections][:body]
15
15
 
16
16
  @note = ::Evernote::EDAM::Type::Note.new
17
17
 
18
18
  # data which maps directly to the Type::Note object
19
19
  self.colour = conf[:colour] || 0xffffff
20
- self.body = conf[:body]
21
20
  self.created = conf[:created_on] || DateTime.now
22
21
 
22
+ note_content = ''
23
+ note_content += conf[:sections][:header] unless conf[:sections][:header] == 'nil'
24
+ conf[:sections][:body]&.map { |el| note_content += "<h2>#{el}</h2>" }
25
+ note_content += conf[:sections][:footer] unless conf[:sections][:footer] == 'nil'
26
+ self.body = note_content
27
+
23
28
  @note.title = conf[:title]
24
29
  @note.tagNames = conf[:tags] || []
25
30
  @note.resources = []
26
31
 
27
32
  # data that must be processed first
28
- @notebook = conf[:parent_notebook] || Entity::Notebook.new.default.to_s
33
+ @notebook = conf[:notebook] || Entity::Notebook.new.default.to_s
29
34
  @resources = conf[:file] || []
30
35
  @shareable = conf[:share_note] || false
31
36
  @updated = conf[:updated_on] || nil
@@ -1,5 +1,5 @@
1
1
  module Evertils
2
2
  module Common
3
- VERSION = '0.3.9'.freeze
3
+ VERSION = '0.3.10'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evertils-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2019-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -154,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.6.12
157
+ rubygems_version: 3.0.1
159
158
  signing_key:
160
159
  specification_version: 4
161
160
  summary: EN (heart) CLI