ohac-ricalv 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +0 -0
  2. data/bin/ricalv +3 -0
  3. data/lib/ricalv.rb +112 -0
  4. metadata +65 -0
data/README ADDED
File without changes
data/bin/ricalv ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'ricalv'
data/lib/ricalv.rb ADDED
@@ -0,0 +1,112 @@
1
+ require 'rubygems'
2
+ require 'icalendar'
3
+ require 'fileutils'
4
+ require 'digest'
5
+
6
+ WEEKTABLE = { 'SU' => 7, 'MO' => 1, 'TU' => 2,
7
+ 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6 }
8
+ KEYS = [ 'FREQ', 'BYDAY', 'BYMONTH', 'WKST', 'UNTIL', 'INTERVAL' ]
9
+ WEEKTOSTR = { 0 => 'Sun', 1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu',
10
+ 5 => 'Fri', 6 => 'Sat' }
11
+
12
+ today = Date.today
13
+ date_end = today + 365 * 3
14
+
15
+ HOME = ENV['HOME']
16
+ SETTING = "#{HOME}/.ricalvrc"
17
+ CACHEDIR = "#{HOME}/.ricalv.d/cache"
18
+ unless File.exists?(SETTING)
19
+ puts "no #{SETTING}"
20
+ exit 1
21
+ end
22
+ icss = File.open(SETTING) { |f| f.readlines.map(&:chop) }
23
+ icss = icss.map { |fn|
24
+ case fn
25
+ when /\A\z/
26
+ when /^#/
27
+ nil
28
+ when /^\//
29
+ fn
30
+ when /http:\/\//
31
+ FileUtils.mkdir_p(CACHEDIR)
32
+ d = CACHEDIR + '/' + Digest::MD5.hexdigest(fn)
33
+ `wget -q -O #{d} #{fn}`
34
+ d
35
+ else
36
+ HOME + '/' + fn
37
+ end
38
+ }.select{|ics| !ics.nil?}
39
+
40
+ calss = icss.map { |fn|
41
+ File.open(fn) { |f| Icalendar.parse(f) }
42
+ }
43
+
44
+ items = calss.map { |cals|
45
+ cals.map { |cal|
46
+ cal.events.map { |event|
47
+ lines = []
48
+ d = Date.parse(event.dtstart.to_s)
49
+ lines << { :d => d, :e => event }
50
+ rrule = event.properties["rrule"]
51
+ if rrule
52
+ rulehash = {}
53
+ rule = rrule[0].split(";")
54
+ rule.each do |item|
55
+ a, b = item.split("=")
56
+ rulehash[a] = b
57
+ end
58
+ yearly = false
59
+ ud = date_end
60
+ mon = nil
61
+ day = nil
62
+ week = nil
63
+ KEYS.each do |key|
64
+ v = rulehash[key]
65
+ next unless v
66
+ case key
67
+ when 'WKST'
68
+ next
69
+ when 'FREQ'
70
+ yearly = true
71
+ when 'UNTIL'
72
+ ud = Date.parse(v)
73
+ when 'INTERVAL'
74
+ v = v.to_i
75
+ next if v == 1
76
+ v = "interval #{v}"
77
+ when 'BYMONTH'
78
+ next unless rulehash.has_key?('BYDAY')
79
+ mon = v.to_i
80
+ when 'BYDAY'
81
+ day = v[0,1].to_i
82
+ week = WEEKTABLE[v[1,2]]
83
+ else
84
+ end
85
+ end
86
+ if yearly
87
+ d = d.next_year
88
+ d = Date.new(d.year, mon, 1) if mon
89
+ while d <= ud
90
+ if day
91
+ d += 1 while d.cwday != week
92
+ d += (day - 1) * 7
93
+ end
94
+ lines << { :d => d, :e => event }
95
+ d = d.next_year
96
+ d = Date.new(d.year, mon, 1) if mon
97
+ end
98
+ end
99
+ end
100
+ lines
101
+ }
102
+ }
103
+ }.flatten
104
+
105
+ items << {:d => today, :t => '*** TODAY ***'}
106
+
107
+ items = items.select{|v|
108
+ d = v[:d]
109
+ d.year == today.year && d.month == today.month
110
+ }
111
+ items = items.map{|v| "#{v[:d].to_s}(#{WEEKTOSTR[v[:d].wday]}) #{v[:t] || v[:e].summary}"}
112
+ items.sort.each{|v| puts v}
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohac-ricalv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - OHASHI Hideya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: icalendar
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.0
24
+ version:
25
+ description: iCalendar viewer for Ruby.
26
+ email: ohachige@gmail.com
27
+ executables:
28
+ - ricalv
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README
35
+ - lib/ricalv.rb
36
+ - bin/ricalv
37
+ has_rdoc: true
38
+ homepage: http://github.com/ohac/ricalv
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --inline-source
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: ricalv
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: iCalendar viewer for Ruby.
64
+ test_files: []
65
+