ohac-rical 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +0 -0
  2. data/lib/rical.rb +112 -0
  3. metadata +64 -0
data/README ADDED
File without changes
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/ruby1.9
2
+ require 'rubygems'
3
+ require 'icalendar'
4
+ require 'fileutils'
5
+ require 'digest'
6
+
7
+ WEEKTABLE = { 'SU' => 7, 'MO' => 1, 'TU' => 2,
8
+ 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6 }
9
+ KEYS = [ 'FREQ', 'BYDAY', 'BYMONTH', 'WKST', 'UNTIL', 'INTERVAL' ]
10
+ WEEKTOSTR = { 0 => 'Sun', 1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu',
11
+ 5 => 'Fri', 6 => 'Sat' }
12
+
13
+ today = Date.today
14
+ date_end = today + 365 * 3
15
+
16
+ HOME = ENV['HOME']
17
+ SETTING = "#{HOME}/.icalrc"
18
+ CACHEDIR = "#{HOME}/.ical.d/cache"
19
+ unless File.exists?(SETTING)
20
+ puts "no #{SETTING}"
21
+ exit 1
22
+ end
23
+ icss = File.open(SETTING) { |f| f.readlines.map(&:chop) }
24
+ icss = icss.map { |fn|
25
+ case fn
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,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohac-rical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
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
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README
35
+ - lib/rical.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/ohac/rical
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --inline-source
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project: rical
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: iCalendar viewer for Ruby.
63
+ test_files: []
64
+