gnu-remind 0.1.5 → 0.1.6

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: c8302802a937430ef1ad975d6616ec60e3426f571ab67362f618396623184469
4
- data.tar.gz: bab3dbb5c8cec7b55e84caa4e30bb7f31fccf60feb9ebfec9232c796d98cc438
3
+ metadata.gz: f610a49a3e80516e18ba70530fe50d0b50a666b3465922d8ed6157d70e6ee203
4
+ data.tar.gz: 6e0574e377bec86bb7688c2a1aace08cb04ef69cfcabbca4c75450cfd6e771f9
5
5
  SHA512:
6
- metadata.gz: 432e323c67bb3b876db61bc967bb2dedabee7ff5ed2f73a3fce029f9c2f1efb00b28464c7ebf6d4a64827fa8345ce1da5b3163e81956cca1fb796c7c999b9921
7
- data.tar.gz: f7757d9b561d015faa63880d888447739b2a6317e462cc1b65a9f794309e81ebe11f8ff45fba35b76b519ae4e0fa35fe9e0949ee1c687cf5440e8a3252d80927
6
+ metadata.gz: 87646938569350ea700426211dabceeee39503dfde78ac240fcf6a03d35310832f96126cc0c1673b9bb3d18efb38327fd24d13f3c93c25d5a0d54c74ea596a3d
7
+ data.tar.gz: 2520562a704f65c70b347c07efff3ab32bba6ac0f8b337718b9a14bb53fa3b446fc23e84a782832d8045f1c72fff7ce580f1b61482678879cd9b12c37cdc0369
@@ -0,0 +1,37 @@
1
+ module EVENT
2
+ class E
3
+ def initialize i
4
+ @event = Nickel.parse i
5
+ puts %[EVENT::E: #{@event}]
6
+ if event?
7
+ @message = @event.message
8
+ else
9
+ t = Time.now.utc
10
+ @message = i
11
+ end
12
+ end
13
+ def event?
14
+ if %[#{@event.message}].length > 0 && @event.occurrences.length > 0
15
+ return true
16
+ else
17
+ return false
18
+ end
19
+ end
20
+ def each &b
21
+ @event.occurrences.each { |e|
22
+ h = {
23
+ message: @message,
24
+ date: e.start_date.to_date.strftime("%-d %b %Y"),
25
+ hour: e.start_time.to_time.strftime("%k"),
26
+ minute: e.start_time.to_time.strftime("%M")
27
+ }
28
+ puts %[each message: #{h}]
29
+ b.call(h, e)
30
+ }
31
+ return nil
32
+ end
33
+ end
34
+ def self.[] k
35
+ E.new(k)
36
+ end
37
+ end
data/lib/remind/remind.rb CHANGED
@@ -1,83 +1,76 @@
1
-
2
- class E
3
- def initialize k
4
- @id = k
5
- @r = Hash.new { |h,k| h[k] = R.new(k) }
6
- clear!
7
- end
8
- def id; @id; end
9
-
10
- def [] k
11
- @rem << k
12
- @r[k]
13
- end
14
-
15
- def agenda
16
- `remind -t1 rem/#{@id}.rem`.split("\n\n")
17
- end
18
-
19
- def clear!
20
- @rem = []
21
- end
22
-
23
- def to_rem
24
- a = [];
25
- @rem.each { |e| a << @r[e].to_rem }
26
- return a.join("\n")
27
- end
28
-
29
- def to_rem!
30
- if !Dir.exist? "rem"
31
- Dir.mkdir("rem")
1
+ module REM
2
+ class E
3
+ def initialize k
4
+ @id = k
5
+ @r = Hash.new { |h,k| h[k] = R.new(k) }
6
+ clear!
32
7
  end
33
- File.open("rem/#{@id}.rem",'w') { |f| f.write(to_rem); }
34
- end
35
- end
36
-
37
-
38
- class R
39
-
40
- attr_accessor :attr
41
-
42
- def initialize k
43
- @id = k
44
- @attr = {}
45
- end
46
-
47
- def id; @id; end
48
-
49
- def to_rem
50
- a, i = [], [ @id ]
51
- if @attr.has_key? :date
52
- a << %[#{@attr[:date]}]
53
- if @attr.has_key? :lead
54
- a << %[++#{@attr[:lead]}]
55
- end
56
- if @attr.has_key? :repeat
57
- a << %[*#{@attr[:repeat]}]
58
- end
59
- if @attr.has_key? :until
60
- a << %[UNTIL #{@attr[:until]}]
61
- end
8
+ def id; @id; end
9
+
10
+ def [] k
11
+ @rem << k
12
+ @rem.uniq
13
+ @r[k]
14
+ end
15
+
16
+ def get a
17
+ `remind #{a} rem/#{@id}.rem`.split("\n\n")
18
+ end
19
+
20
+ def clear!
21
+ @rem = []
62
22
  end
63
- if @attr.has_key? :hour
64
- if @attr.has_key? :minute
65
- a << %[AT #{@attr[:hour]}:#{@attr[:minute]}]
23
+
24
+ def to_rem
25
+ a = [];
26
+ @rem.each { |e| a << @r[e].to_rem }
27
+ return a.join("\n")
28
+ end
29
+
30
+ def to_rem! h={}
31
+ if !Dir.exist? "rem"
32
+ Dir.mkdir("rem")
33
+ end
34
+ if h[:append] == true
35
+ File.open("rem/#{@id}.rem",'a') { |f| f.write(to_rem); }
66
36
  else
67
- a << %[AT #{@attr[:hour]}:00]
37
+ File.open("rem/#{@id}.rem",'w') { |f| f.write(to_rem); }
68
38
  end
69
39
  end
70
- if @attr.has_key? :duration
71
- i << %[for #{@attr[:duration]} hours]
40
+ end
41
+
42
+
43
+ class R
44
+
45
+ attr_accessor :attr
46
+
47
+ def initialize k
48
+ @id = k
49
+ @attr = {}
72
50
  end
73
- if @attr.has_key? :at
74
- i << %[at #{@attr[:at]}]
51
+
52
+ def id; @id; end
53
+
54
+ def to_rem
55
+ puts %[R[#{@id}] #{@attr}]
56
+ a, i = [], [ @id ]
57
+ if @attr.has_key? :date
58
+ a << %[#{@attr[:date]}]
59
+ if @attr.has_key? :lead
60
+ a << %[++#{@attr[:lead]}]
61
+ end
62
+ end
63
+ if @attr.has_key? :hour
64
+ if @attr.has_key? :minute
65
+ a << %[AT #{@attr[:hour]}:#{@attr[:minute]}]
66
+ else
67
+ a << %[AT #{@attr[:hour]}:00]
68
+ end
69
+ end
70
+ return %[REM #{a.join(" ")} MSG #{i.join(" ")}\n]
75
71
  end
76
- return %[REM #{a.join(" ")} MSG #{i.join(" ")}]
77
72
  end
78
- end
79
-
80
- module REM
73
+
81
74
  @@REM = Hash.new { |h,k| h[k] = E.new(k) }
82
75
  def self.[] k
83
76
  @@REM[k]
@@ -86,4 +79,3 @@ module REM
86
79
  @@REM.keys
87
80
  end
88
81
  end
89
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Remind
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/remind.rb CHANGED
@@ -1,80 +1,77 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'erb'
4
+
3
5
  require 'faraday'
4
6
 
5
7
  require 'icalendar'
6
8
 
9
+ require 'nickel'
10
+
7
11
  require_relative "remind/version"
8
12
 
9
13
  require_relative "remind/remind"
10
14
 
11
15
  require_relative "remind/calendar"
12
16
 
17
+ require_relative "remind/event"
18
+
13
19
  module Remind
14
20
  class Error < StandardError; end
21
+
15
22
  @@REM = REM['reminders']
23
+
16
24
  @@INIT = []
17
- @@URL = []
18
25
  def self.init h={}
19
26
  @@INIT << h
20
27
  end
21
28
 
29
+ @@URL = []
22
30
  def self.url u
23
31
  @@URL << u
24
32
  end
25
33
 
34
+ @@SRC = []
35
+ def self.src k
36
+ @@SRC << k
37
+ end
38
+
26
39
  def self.rebuild!
27
40
  @@REM.clear!
41
+
28
42
  [@@INIT].flatten.each do |x|
43
+ puts %[rebuild! x: #{x}]
29
44
  @@REM[x[:what]].attr = { date: x[:when] }
30
45
  end
46
+
31
47
  @@URL.each do |u|
48
+ puts %[rebuild! u: #{u}]
32
49
  CAL.from_url(u).each do |e|
33
50
  d = e.when[:begin].to_time.localtime.strftime("%Y/%m/%d-%R")
34
- h = {
35
- date: e.when[:begin].to_time.localtime.strftime("%-d %b %Y"),
36
- hour: e.when[:begin].to_time.localtime.strftime("%k"),
37
- minute: e.when[:begin].to_time.localtime.strftime("%M"),
38
- at: e.where,
39
- type: e.who,
40
- lead: 1
41
- }
51
+ h = { date: e.when[:begin].to_time.localtime.strftime("%-d %b %Y"), hour: e.when[:begin].to_time.localtime.strftime("%k"), minute: e.when[:begin].to_time.localtime.strftime("%M"), lead: 1 }
42
52
  k = %[#{e.what} #{h[:type]} #{d}]
43
53
  @@REM[k].attr = h
44
54
  end
45
55
  end
46
- end
47
-
48
- def self.remote x, u
49
- r = REM[x]
50
- r.clear!
51
- Remind.rebuild!
52
- CAL.from_url(u).each do |e|
53
- d = e.when[:begin].to_time.localtime.strftime("%Y/%m/%d-%R")
54
- h = {
55
- date: e.when[:begin].to_time.localtime.strftime("%-d %b %Y"),
56
- hour: e.when[:begin].to_time.localtime.strftime("%k"),
57
- minute: e.when[:begin].to_time.localtime.strftime("%M"),
58
- at: e.where,
59
- type: e.who
60
- }
61
-
62
- k = %[#{e.what} #{h[:type]} #{d}]
63
- puts "#{k}: #{h}"
64
- r[k].attr = h
65
- @@REM[k].attr = h
66
- end
67
- r.to_rem!
56
+
68
57
  @@REM.to_rem!
69
- return nil
70
- end
58
+ end
71
59
 
72
- def self.[] k
73
- REM[k].agenda[1..-1]
60
+ def self.remind k, *src
61
+ REM[k].clear!
62
+ [src].flatten.each do |e|
63
+ EVENT[e].each do |ee|
64
+ REM[k][%[#{ee[:message]} #{ee[:date]}]].attr = { date: ee[:date], hour: ee[:hour], minute: ee[:minute], lead: 1 }
65
+ end
66
+ end
67
+ REM[k].to_rem! append: true
74
68
  end
75
69
 
76
- def self.all
77
- @@REM.to_rem!
78
- @@REM.agenda[1..-1]
70
+ def self.get a, k
71
+ REM[k].get(a)[1..-1]
72
+ end
73
+
74
+ def self.get! a
75
+ @@REM.get(a)[1..-1]
79
76
  end
80
77
  end
data/remind.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  # Uncomment to register a new dependency of your gem
34
34
  spec.add_dependency "faraday"
35
35
  spec.add_dependency "icalendar"
36
+ spec.add_dependency "nickel"
36
37
  # For more information and examples about making a new gem, check out our
37
38
  # guide at: https://bundler.io/guides/creating_gem.html
38
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnu-remind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-18 00:00:00.000000000 Z
11
+ date: 2024-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nickel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: A wrapper around gnu remind leveraging ics files via url or locally.
42
56
  email:
43
57
  - xorgnak@gmail.com
@@ -52,6 +66,7 @@ files:
52
66
  - Rakefile
53
67
  - lib/remind.rb
54
68
  - lib/remind/calendar.rb
69
+ - lib/remind/event.rb
55
70
  - lib/remind/remind.rb
56
71
  - lib/remind/version.rb
57
72
  - remind.gemspec