gnu-remind 0.1.4 → 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: 0b779171299941272c40a69f2c88d4b34bc5fc85dc239a75ae0d9e8a7f8eccb4
4
- data.tar.gz: 44e7b58ad3a0ff1cae715438f216761eb345c0a2966da71a499e59b8998eef59
3
+ metadata.gz: f610a49a3e80516e18ba70530fe50d0b50a666b3465922d8ed6157d70e6ee203
4
+ data.tar.gz: 6e0574e377bec86bb7688c2a1aace08cb04ef69cfcabbca4c75450cfd6e771f9
5
5
  SHA512:
6
- metadata.gz: 633cadf0e0eec59b72bdd8611ed087329ad98f00ddb3bf92da7b81bb9b0748bef7c87b48c49de7798b293619c3429990374beab768ac0e8a48c0eb3e4d75b1ec
7
- data.tar.gz: 0d6a7e51f5236a36038ce5605a8332183cd1c145e05540feef9984e3106c8ceab6bd3babe712b9ae8548c525cbd7745d2daf69bca3dc43873eecdbb6a11f851a
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.4"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/remind.rb CHANGED
@@ -1,63 +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']
16
- def self.make x, u, *i
17
- r = REM[x]
18
- r.clear!
23
+
24
+ @@INIT = []
25
+ def self.init h={}
26
+ @@INIT << h
27
+ end
28
+
29
+ @@URL = []
30
+ def self.url u
31
+ @@URL << u
32
+ end
33
+
34
+ @@SRC = []
35
+ def self.src k
36
+ @@SRC << k
37
+ end
38
+
39
+ def self.rebuild!
19
40
  @@REM.clear!
20
- [i].flatten.each do |x|
21
- r[x[:what]].attr = { date: x[:when] }
41
+
42
+ [@@INIT].flatten.each do |x|
43
+ puts %[rebuild! x: #{x}]
22
44
  @@REM[x[:what]].attr = { date: x[:when] }
23
45
  end
24
- if ENV.has_key? 'ICS'
25
- CAL.from_url(ENV['ICS']).each do |e|
26
- h = {
27
- date: e.when[:begin].to_time.localtime.strftime("%-d %b %Y"),
28
- hour: e.when[:begin].to_time.localtime.strftime("%k"),
29
- minute: e.when[:begin].to_time.localtime.strftime("%M"),
30
- at: e.where,
31
- type: e.who,
32
- lead: 30
33
- }
34
- r[e.what].attr = h
35
- @@REM[e.what].attr = h
46
+
47
+ @@URL.each do |u|
48
+ puts %[rebuild! u: #{u}]
49
+ CAL.from_url(u).each do |e|
50
+ d = e.when[:begin].to_time.localtime.strftime("%Y/%m/%d-%R")
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 }
52
+ k = %[#{e.what} #{h[:type]} #{d}]
53
+ @@REM[k].attr = h
36
54
  end
37
55
  end
38
- CAL.from_url(u).each do |e|
39
- d = e.when[:begin].to_time.localtime.strftime("%Y/%m/%d-%R")
40
- h = {
41
- date: e.when[:begin].to_time.localtime.strftime("%-d %b %Y"),
42
- hour: e.when[:begin].to_time.localtime.strftime("%k"),
43
- minute: e.when[:begin].to_time.localtime.strftime("%M"),
44
- at: e.where,
45
- type: e.who
46
- }
47
-
48
- k = %[#{e.what} #{h[:type]} #{d}]
49
- puts "#{k}: #{h}"
50
- r[k].attr = h
51
- @@REM[k].attr = h
52
- end
53
- r.to_rem!
56
+
54
57
  @@REM.to_rem!
55
- return nil
58
+ end
59
+
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
56
68
  end
57
- def self.[] k
58
- REM[k].agenda[1..-1]
69
+
70
+ def self.get a, k
71
+ REM[k].get(a)[1..-1]
59
72
  end
60
- def self.all
61
- @@REM.agenda[1..-1]
73
+
74
+ def self.get! a
75
+ @@REM.get(a)[1..-1]
62
76
  end
63
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.4
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