ics 0.1 → 0.2
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.
- data/.rvmrc +1 -1
- data/Gemfile.lock +12 -12
- data/HISTORY.md +8 -0
- data/README.rdoc +2 -47
- data/ics.gemspec +1 -1
- data/lib/ics/event.rb +30 -24
- data/lib/ics/version.rb +1 -1
- data/spec/event_spec.rb +9 -33
- data/spec/{example_events.ics → support/fixtures/example_events.ics} +0 -0
- metadata +64 -72
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm
|
1
|
+
rvm --create 1.9.3-p327@ics
|
data/Gemfile.lock
CHANGED
@@ -6,19 +6,19 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ZenTest (4.
|
9
|
+
ZenTest (4.8.3)
|
10
10
|
autotest (4.4.6)
|
11
11
|
ZenTest (>= 4.4.1)
|
12
|
-
awesome_print (
|
13
|
-
diff-lcs (1.1.
|
14
|
-
rspec (2.
|
15
|
-
rspec-core (~> 2.
|
16
|
-
rspec-expectations (~> 2.
|
17
|
-
rspec-mocks (~> 2.
|
18
|
-
rspec-core (2.
|
19
|
-
rspec-expectations (2.
|
20
|
-
diff-lcs (~> 1.1.
|
21
|
-
rspec-mocks (2.
|
12
|
+
awesome_print (1.1.0)
|
13
|
+
diff-lcs (1.1.3)
|
14
|
+
rspec (2.12.0)
|
15
|
+
rspec-core (~> 2.12.0)
|
16
|
+
rspec-expectations (~> 2.12.0)
|
17
|
+
rspec-mocks (~> 2.12.0)
|
18
|
+
rspec-core (2.12.2)
|
19
|
+
rspec-expectations (2.12.1)
|
20
|
+
diff-lcs (~> 1.1.3)
|
21
|
+
rspec-mocks (2.12.1)
|
22
22
|
|
23
23
|
PLATFORMS
|
24
24
|
ruby
|
@@ -27,4 +27,4 @@ DEPENDENCIES
|
|
27
27
|
autotest
|
28
28
|
awesome_print
|
29
29
|
ics!
|
30
|
-
rspec
|
30
|
+
rspec
|
data/HISTORY.md
ADDED
data/README.rdoc
CHANGED
@@ -12,51 +12,6 @@ ICS is a library that reads ICS files and parses them into ICS::Event objects.
|
|
12
12
|
events.map(&:summary)
|
13
13
|
#=> ['Walk dog', 'Solve world hunger, tell noone', ...]
|
14
14
|
|
15
|
-
=== Longer version
|
16
|
-
|
17
|
-
The ICS::Event class can read in and parse an exported .ics file. For example, from iCal, export a calendar (select calendar, File, Export..., Export...):
|
18
|
-
ICS::Event.file(File.open('calendar.ics'))
|
19
|
-
will return an array of events with whatever attributes are in the .ics file for each event. The ICS::Event object will have a method name for each attribute in lower case form.
|
20
|
-
# calendar.ics
|
21
|
-
...
|
22
|
-
SUMMARY:Grocery shopping
|
23
|
-
...
|
24
|
-
|
25
|
-
# ruby environment
|
26
|
-
event.summary
|
27
|
-
#=> 'Grocery shopping'
|
28
|
-
|
29
|
-
Here are a list of known attributes:
|
30
|
-
* TRANSP
|
31
|
-
* DTEND
|
32
|
-
* UID
|
33
|
-
* DTSTAMP
|
34
|
-
* LOCATION
|
35
|
-
* DESCRIPTION
|
36
|
-
* URL
|
37
|
-
* STATUS
|
38
|
-
* SEQUENCE
|
39
|
-
* SUMMARY
|
40
|
-
* DTSTART
|
41
|
-
* CREATED
|
42
|
-
# For the alarm...
|
43
|
-
* # BEGIN:VALARM (ignored)
|
44
|
-
* X-WR-ALARMUID
|
45
|
-
* TRIGGER
|
46
|
-
* ATTACH
|
47
|
-
* ACTION
|
48
|
-
* # END:VALARM (ignored)
|
49
|
-
|
50
|
-
=== Data type casting
|
51
|
-
|
52
|
-
By default, each attribute method returns a string literal. For convenience, attribute methods can be easily defined in the ICS::Event class for customized behavior. Currently <tt>ICS::Event#dtstart</tt> is the only one that is defined:
|
53
|
-
event.dtstart.class
|
54
|
-
#=> Time
|
55
|
-
|
56
|
-
=== More "Railsy"
|
57
|
-
|
58
|
-
<tt>ICS::Event#started_at</tt> is an alias for <tt>ICS::Event#dtstart</tt>. <tt>ICS::Event#started_on</tt> returns a Date object converted from <tt>ICS::Event#dtstart</tt>. More later...
|
59
|
-
|
60
15
|
=== Metadata
|
61
16
|
|
62
17
|
Some attributes have some metadata attached to them. For example, sometimes the DTSTART attribute has the time zone:
|
@@ -69,6 +24,6 @@ As of this version, metadata is ignored.
|
|
69
24
|
|
70
25
|
gem install ics
|
71
26
|
|
72
|
-
==
|
27
|
+
== TODO
|
73
28
|
|
74
|
-
|
29
|
+
* Multiple alarms?
|
data/ics.gemspec
CHANGED
data/lib/ics/event.rb
CHANGED
@@ -4,31 +4,30 @@ module ICS
|
|
4
4
|
|
5
5
|
class Event
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
attr_accessor :action
|
8
|
+
attr_accessor :alarmuid
|
9
|
+
attr_accessor :attach
|
10
|
+
attr_accessor :created
|
11
|
+
attr_accessor :description
|
12
|
+
attr_accessor :dtend
|
13
|
+
attr_accessor :dtstamp
|
14
|
+
attr_accessor :dtstart
|
15
|
+
attr_accessor :location
|
16
|
+
attr_accessor :sequence
|
17
|
+
attr_accessor :status
|
18
|
+
attr_accessor :summary
|
19
|
+
attr_accessor :transp
|
20
|
+
attr_accessor :trigger
|
21
|
+
attr_accessor :uid
|
22
|
+
attr_accessor :url
|
23
|
+
attr_accessor :x_wr_alarmuid
|
24
|
+
|
9
25
|
def initialize(attributes = {})
|
10
|
-
@attributes = attributes
|
11
26
|
attributes.each do |key, val|
|
12
|
-
|
13
|
-
self.class.send :define_method, key do
|
14
|
-
@attributes[key]
|
15
|
-
end
|
16
|
-
end
|
27
|
+
send("#{key}=", val)
|
17
28
|
end
|
18
29
|
end
|
19
30
|
|
20
|
-
# Return time object.
|
21
|
-
# Assumes time in UTC.
|
22
|
-
def dtstart
|
23
|
-
return nil unless @attributes[:dtstart]
|
24
|
-
DateTime.parse(@attributes[:dtstart]).to_time.utc
|
25
|
-
end
|
26
|
-
alias_method :started_at, :dtstart
|
27
|
-
|
28
|
-
def started_on
|
29
|
-
dtstart.to_date if dtstart
|
30
|
-
end
|
31
|
-
|
32
31
|
class << self
|
33
32
|
|
34
33
|
# Given an exported ical file, parse it and create events.
|
@@ -38,19 +37,26 @@ module ICS
|
|
38
37
|
line_ending = $/
|
39
38
|
content.split("BEGIN:VEVENT#{line_ending}")[1..-1].map do |data_string|
|
40
39
|
data_string = data_string.split("END:VEVENT#{line_ending}").first
|
41
|
-
|
40
|
+
parse(data_string)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
44
|
+
# Parse data and return new Event.
|
45
45
|
def parse(str)
|
46
|
-
str.split($/).inject({}) do |hash, line|
|
46
|
+
attributes = str.split($/).inject({}) do |hash, line|
|
47
47
|
key, value = line.split(':', 2)
|
48
|
-
next hash if key =~ /^BEGIN
|
48
|
+
next hash if key =~ /^BEGIN$|^END$/ # Ignore any other book ends.
|
49
49
|
value = value.chomp if value
|
50
|
-
key =
|
50
|
+
key =
|
51
|
+
key.
|
52
|
+
split(';', 2).
|
53
|
+
first. # Ignore extra data other than just the name of the attribute.
|
54
|
+
gsub('-', '_') # underscore.
|
51
55
|
hash[key.downcase.to_sym] = value
|
52
56
|
hash
|
53
57
|
end
|
58
|
+
|
59
|
+
new(attributes)
|
54
60
|
end
|
55
61
|
|
56
62
|
end
|
data/lib/ics/version.rb
CHANGED
data/spec/event_spec.rb
CHANGED
@@ -2,46 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ICS::Event do
|
4
4
|
|
5
|
-
it 'parses event data string and
|
6
|
-
ICS::Event.parse("
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should read a file, parse it, and return an array of events' do
|
10
|
-
file = file_with_content(<<-END)
|
11
|
-
BEGIN:VEVENT
|
12
|
-
INDEX:0
|
13
|
-
END:VEVENT
|
14
|
-
BEGIN:VEVENT
|
15
|
-
INDEX:1
|
16
|
-
END:VEVENT
|
17
|
-
END
|
18
|
-
events = ICS::Event.file(file)
|
19
|
-
events.size.should == 2
|
20
|
-
events.each_with_index do |event, i|
|
21
|
-
event.index.should == i.to_s
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should be initialized with a hash of attributes and have keys defined as methods returning values' do
|
26
|
-
event = ICS::Event.new(:attribute => '1')
|
27
|
-
event.should respond_to(:attribute)
|
28
|
-
event.attribute.should == '1'
|
29
|
-
end
|
5
|
+
it 'parses event data string and returns new Event' do
|
6
|
+
event = ICS::Event.parse("SUMMARY:value with spaces\nSTATUS:val")
|
30
7
|
|
31
|
-
|
32
|
-
|
33
|
-
event = ICS::Event.new(:dtstart => time.strftime('%Y%m%dT%H%M%SZ'))
|
34
|
-
event.dtstart.to_i.should == time.to_i
|
8
|
+
event.summary.should == 'value with spaces'
|
9
|
+
event.status.should == 'val'
|
35
10
|
end
|
36
11
|
|
37
|
-
it 'should
|
38
|
-
events = ICS::Event.file(File.open('spec/example_events.ics'))
|
12
|
+
it 'should read a file, parse it, and return an array of events' do
|
13
|
+
events = ICS::Event.file(File.open('spec/support/fixtures/example_events.ics'))
|
39
14
|
events.size.should == 2
|
40
15
|
end
|
41
16
|
|
42
17
|
it 'should parse attributes ignoring extra data like time zone for DTSTART' do
|
43
|
-
data = 'DTSTART;TZID=asdfasdf:
|
44
|
-
ICS::Event.parse(data)
|
18
|
+
data = 'DTSTART;TZID=asdfasdf:20100331T200000'
|
19
|
+
event = ICS::Event.parse(data)
|
20
|
+
event.dtstart.should == '20100331T200000'
|
45
21
|
end
|
46
22
|
|
47
23
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,77 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ics
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
version: "0.1"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
9
6
|
platform: ruby
|
10
|
-
authors:
|
7
|
+
authors:
|
11
8
|
- Jared Ning
|
12
9
|
autorequire:
|
13
10
|
bindir: bin
|
14
11
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
dependencies:
|
19
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
20
15
|
name: autotest
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 0
|
29
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
30
22
|
type: :development
|
31
|
-
version_requirements: *id001
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: awesome_print
|
34
23
|
prerelease: false
|
35
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: awesome_print
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
36
33
|
none: false
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
|
41
|
-
- 0
|
42
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
43
38
|
type: :development
|
44
|
-
version_requirements: *id002
|
45
|
-
- !ruby/object:Gem::Dependency
|
46
|
-
name: rspec
|
47
39
|
prerelease: false
|
48
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
- 2
|
55
|
-
- 3
|
56
|
-
- 0
|
57
|
-
version: 2.3.0
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.12'
|
58
54
|
type: :development
|
59
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.12'
|
60
62
|
description: Parse exported .ics files into Event objects.
|
61
|
-
email:
|
63
|
+
email:
|
62
64
|
- jared@redningja.com
|
63
65
|
executables: []
|
64
|
-
|
65
66
|
extensions: []
|
66
|
-
|
67
67
|
extra_rdoc_files: []
|
68
|
-
|
69
|
-
files:
|
68
|
+
files:
|
70
69
|
- .gitignore
|
71
70
|
- .rspec
|
72
71
|
- .rvmrc
|
73
72
|
- Gemfile
|
74
73
|
- Gemfile.lock
|
74
|
+
- HISTORY.md
|
75
75
|
- README.rdoc
|
76
76
|
- Rakefile
|
77
77
|
- ics.gemspec
|
@@ -79,43 +79,35 @@ files:
|
|
79
79
|
- lib/ics/event.rb
|
80
80
|
- lib/ics/version.rb
|
81
81
|
- spec/event_spec.rb
|
82
|
-
- spec/example_events.ics
|
83
82
|
- spec/spec_helper.rb
|
83
|
+
- spec/support/fixtures/example_events.ics
|
84
84
|
- spec/support/macros.rb
|
85
|
-
has_rdoc: true
|
86
85
|
homepage:
|
87
86
|
licenses: []
|
88
|
-
|
89
87
|
post_install_message:
|
90
88
|
rdoc_options: []
|
91
|
-
|
92
|
-
require_paths:
|
89
|
+
require_paths:
|
93
90
|
- lib
|
94
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
92
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
101
|
-
version: "0"
|
102
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
98
|
none: false
|
104
|
-
requirements:
|
105
|
-
- -
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
|
108
|
-
- 0
|
109
|
-
version: "0"
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
110
103
|
requirements: []
|
111
|
-
|
112
104
|
rubyforge_project: ics
|
113
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.8.24
|
114
106
|
signing_key:
|
115
107
|
specification_version: 3
|
116
108
|
summary: Read .ics files
|
117
|
-
test_files:
|
109
|
+
test_files:
|
118
110
|
- spec/event_spec.rb
|
119
|
-
- spec/example_events.ics
|
120
111
|
- spec/spec_helper.rb
|
112
|
+
- spec/support/fixtures/example_events.ics
|
121
113
|
- spec/support/macros.rb
|