icalendar 0.95
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +56 -0
- data/GPL +340 -0
- data/README +121 -0
- data/Rakefile +101 -0
- data/docs/api/classes/Array.html +146 -0
- data/docs/api/classes/Date.html +157 -0
- data/docs/api/classes/DateTime.html +178 -0
- data/docs/api/classes/Fixnum.html +146 -0
- data/docs/api/classes/Float.html +146 -0
- data/docs/api/classes/Icalendar/Alarm.html +184 -0
- data/docs/api/classes/Icalendar/Base.html +118 -0
- data/docs/api/classes/Icalendar/Calendar.html +411 -0
- data/docs/api/classes/Icalendar/Component.html +306 -0
- data/docs/api/classes/Icalendar/DateProp.html +187 -0
- data/docs/api/classes/Icalendar/DateProp/ClassMethods.html +195 -0
- data/docs/api/classes/Icalendar/Event.html +202 -0
- data/docs/api/classes/Icalendar/Freebusy.html +157 -0
- data/docs/api/classes/Icalendar/InvalidComponentClass.html +117 -0
- data/docs/api/classes/Icalendar/InvalidPropertyValue.html +117 -0
- data/docs/api/classes/Icalendar/Journal.html +190 -0
- data/docs/api/classes/Icalendar/Parameter.html +166 -0
- data/docs/api/classes/Icalendar/Parser.html +447 -0
- data/docs/api/classes/Icalendar/Timezone.html +197 -0
- data/docs/api/classes/Icalendar/Todo.html +199 -0
- data/docs/api/classes/String.html +160 -0
- data/docs/api/classes/Time.html +161 -0
- data/docs/api/created.rid +1 -0
- data/docs/api/files/COPYING.html +163 -0
- data/docs/api/files/GPL.html +531 -0
- data/docs/api/files/README.html +241 -0
- data/docs/api/files/lib/icalendar/base_rb.html +108 -0
- data/docs/api/files/lib/icalendar/calendar_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component/alarm_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component/event_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component/freebusy_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component/journal_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component/timezone_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component/todo_rb.html +101 -0
- data/docs/api/files/lib/icalendar/component_rb.html +101 -0
- data/docs/api/files/lib/icalendar/conversions_rb.html +108 -0
- data/docs/api/files/lib/icalendar/helpers_rb.html +101 -0
- data/docs/api/files/lib/icalendar/parameter_rb.html +101 -0
- data/docs/api/files/lib/icalendar/parser_rb.html +109 -0
- data/docs/api/files/lib/icalendar_rb.html +118 -0
- data/docs/api/fr_class_index.html +48 -0
- data/docs/api/fr_file_index.html +43 -0
- data/docs/api/fr_method_index.html +63 -0
- data/docs/api/index.html +24 -0
- data/docs/api/rdoc-style.css +208 -0
- data/docs/examples/create_cal.rb +40 -0
- data/docs/examples/parse_cal.rb +19 -0
- data/docs/examples/single_event.ics +18 -0
- data/docs/rfcs/rfc2425.pdf +0 -0
- data/docs/rfcs/rfc2426.pdf +0 -0
- data/docs/rfcs/rfc2445.pdf +0 -0
- data/docs/rfcs/rfc2446.pdf +0 -0
- data/docs/rfcs/rfc2447.pdf +0 -0
- data/docs/rfcs/rfc3283.txt +738 -0
- data/lib/icalendar.rb +27 -0
- data/lib/icalendar/#helpers.rb# +92 -0
- data/lib/icalendar/base.rb +31 -0
- data/lib/icalendar/calendar.rb +112 -0
- data/lib/icalendar/component.rb +253 -0
- data/lib/icalendar/component/alarm.rb +35 -0
- data/lib/icalendar/component/event.rb +68 -0
- data/lib/icalendar/component/freebusy.rb +35 -0
- data/lib/icalendar/component/journal.rb +61 -0
- data/lib/icalendar/component/timezone.rb +43 -0
- data/lib/icalendar/component/todo.rb +65 -0
- data/lib/icalendar/conversions.rb +115 -0
- data/lib/icalendar/helpers.rb +109 -0
- data/lib/icalendar/parameter.rb +33 -0
- data/lib/icalendar/parser.rb +395 -0
- data/test/calendar_test.rb +46 -0
- data/test/component/event_test.rb +47 -0
- data/test/component_test.rb +74 -0
- data/test/parser_test.rb +83 -0
- data/test/property_helpers.rb +35 -0
- data/test/simplecal.ics +119 -0
- data/test/single_event.ics +23 -0
- metadata +135 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
module Icalendar
|
9
|
+
# An Alarm calendar component is a grouping of component
|
10
|
+
# properties that is a reminder or alarm for an event or a
|
11
|
+
# to-do. For example, it may be used to define a reminder for a
|
12
|
+
# pending Event or an overdue Todo.
|
13
|
+
class Alarm < Component
|
14
|
+
|
15
|
+
# Single properties
|
16
|
+
ical_property :action
|
17
|
+
ical_property :trigger
|
18
|
+
|
19
|
+
# Single but must appear together
|
20
|
+
ical_property :duration
|
21
|
+
ical_property :repeat
|
22
|
+
|
23
|
+
# Single and only occurring once
|
24
|
+
ical_property :attach, :attachment
|
25
|
+
|
26
|
+
def initialize()
|
27
|
+
super("VALARM")
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_ical
|
32
|
+
print_string {}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
|
9
|
+
module Icalendar
|
10
|
+
# A Event calendar component is a grouping of component
|
11
|
+
# properties, and possibly including Alarm calendar components, that
|
12
|
+
# represents a scheduled amount of time on a calendar. For example, it
|
13
|
+
# can be an activity; such as a one-hour long, department meeting from
|
14
|
+
# 8:00 AM to 9:00 AM, tomorrow. Generally, an event will take up time
|
15
|
+
# on an individual calendar.
|
16
|
+
class Event < Component
|
17
|
+
attr_accessor :alarms
|
18
|
+
|
19
|
+
# Single properties
|
20
|
+
ical_property :klass, nil, :class
|
21
|
+
ical_property :created
|
22
|
+
ical_property :description
|
23
|
+
ical_property :dtstart, :start
|
24
|
+
ical_property :geo
|
25
|
+
ical_property :last_mod, :last_modification
|
26
|
+
ical_property :location
|
27
|
+
ical_property :organizer
|
28
|
+
ical_property :priority
|
29
|
+
ical_property :dtstamp, :timestamp
|
30
|
+
ical_property :seq, :sequence
|
31
|
+
ical_property :status
|
32
|
+
ical_property :summary
|
33
|
+
ical_property :transp, :transparency
|
34
|
+
ical_property :uid, :user_id
|
35
|
+
ical_property :url
|
36
|
+
ical_property :recurid, :recurrence_id
|
37
|
+
|
38
|
+
# Single but mutually exclusive TODO: not testing anything yet
|
39
|
+
ical_property :dtend, :end
|
40
|
+
ical_property :duration
|
41
|
+
|
42
|
+
# Multi-properties
|
43
|
+
ical_multi_property :attach, :attachment, :attachments
|
44
|
+
ical_multi_property :attendee, :attendee, :attendees
|
45
|
+
ical_multi_property :categories, :category, :categories
|
46
|
+
ical_multi_property :comment, :comment, :comments
|
47
|
+
ical_multi_property :contact, :contact, :contacts
|
48
|
+
ical_multi_property :exdate, :exception_date, :exception_dates
|
49
|
+
ical_multi_property :exrule, :exception_rule, :exception_rules
|
50
|
+
ical_multi_property :rstatus, :request_status, :request_statuses
|
51
|
+
ical_multi_property :related_to, :related_to, :related_tos
|
52
|
+
ical_multi_property :resources, :resource, :resources
|
53
|
+
ical_multi_property :rdate, :recurrence_date, :recurrence_dates
|
54
|
+
ical_multi_property :rrule, :recurrence_rule, :recurrence_rules
|
55
|
+
|
56
|
+
def initialize()
|
57
|
+
super("VEVENT")
|
58
|
+
|
59
|
+
@alarms = []
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_ical
|
63
|
+
print_string do |s|
|
64
|
+
@alarms.each { |alarm| s << alarm.to_ical }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
module Icalendar
|
9
|
+
# A Freebusy calendar component is a grouping of
|
10
|
+
# component properties that represents either a request for, a reply to
|
11
|
+
# a request for free or busy time information or a published set of
|
12
|
+
# busy time information.
|
13
|
+
class Freebusy < Component
|
14
|
+
|
15
|
+
# Single properties
|
16
|
+
ical_property :contact
|
17
|
+
ical_property :dtstart, :start
|
18
|
+
ical_property :dtend, :end
|
19
|
+
ical_property :dtstamp, :timestamp
|
20
|
+
ical_property :duration
|
21
|
+
ical_property :organizer
|
22
|
+
ical_property :uid, :user_id
|
23
|
+
ical_property :url
|
24
|
+
|
25
|
+
# Multi-properties
|
26
|
+
ical_multi_property :attendee, :attendee, :attendees
|
27
|
+
ical_multi_property :comment, :comment, :comments
|
28
|
+
ical_multi_property :freebusy, :freebusy, :freebusys
|
29
|
+
ical_multi_property :rstatus, :request_status, :request_statuses
|
30
|
+
|
31
|
+
def initialize()
|
32
|
+
super("VFREEBUSY")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
module Icalendar
|
9
|
+
# A Journal calendar component is a grouping of
|
10
|
+
# component properties that represent one or more descriptive text
|
11
|
+
# notes associated with a particular calendar date. The "DTSTART"
|
12
|
+
# property is used to specify the calendar date that the journal entry
|
13
|
+
# is associated with. Generally, it will have a DATE value data type,
|
14
|
+
# but it can also be used to specify a DATE-TIME value data type.
|
15
|
+
# Examples of a journal entry include a daily record of a legislative
|
16
|
+
# body or a journal entry of individual telephone contacts for the day
|
17
|
+
# or an ordered list of accomplishments for the day. The Journal
|
18
|
+
# calendar component can also be used to associate a document with a
|
19
|
+
# calendar date.
|
20
|
+
class Journal < Component
|
21
|
+
|
22
|
+
# Single properties
|
23
|
+
ical_property :klass, nil, :class
|
24
|
+
ical_property :created
|
25
|
+
ical_property :description
|
26
|
+
ical_property :dtstart, :start
|
27
|
+
ical_property :last_mod, :last_modification
|
28
|
+
ical_property :organizer
|
29
|
+
ical_property :dtstamp, :timestamp
|
30
|
+
ical_property :seq, :sequence
|
31
|
+
ical_property :status
|
32
|
+
ical_property :summary
|
33
|
+
ical_property :uid, :user_id
|
34
|
+
ical_property :url
|
35
|
+
ical_property :recurid, :recurrence_id
|
36
|
+
|
37
|
+
# Multi-properties
|
38
|
+
ical_multi_property :attach, :attachment, :attachments
|
39
|
+
ical_multi_property :attendee, :attendee, :attendees
|
40
|
+
ical_multi_property :categories, :category, :categories
|
41
|
+
ical_multi_property :comment, :comment, :comments
|
42
|
+
ical_multi_property :contact, :contact, :contacts
|
43
|
+
ical_multi_property :exdate, :exception_date, :exception_dates
|
44
|
+
ical_multi_property :exrule, :exception_rule, :exception_rules
|
45
|
+
ical_multi_property :rstatus, :request_status, :request_statuses
|
46
|
+
ical_multi_property :related_to, :related_to, :related_tos
|
47
|
+
ical_multi_property :resources, :resource, :resources
|
48
|
+
ical_multi_property :rdate, :recurrence_date, :recurrence_dates
|
49
|
+
ical_multi_property :rrule, :recurrence_rule, :recurrence_rules
|
50
|
+
|
51
|
+
def initialize()
|
52
|
+
super("VJOURNAL")
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_ical
|
56
|
+
print_string { }
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
module Icalendar
|
9
|
+
# A Timezone is unambiguously defined by the set of time
|
10
|
+
# measurement rules determined by the governing body for a given
|
11
|
+
# geographic area. These rules describe at a minimum the base offset
|
12
|
+
# from UTC for the time zone, often referred to as the Standard Time
|
13
|
+
# offset. Many locations adjust their Standard Time forward or backward
|
14
|
+
# by one hour, in order to accommodate seasonal changes in number of
|
15
|
+
# daylight hours, often referred to as Daylight Saving Time. Some
|
16
|
+
# locations adjust their time by a fraction of an hour. Standard Time
|
17
|
+
# is also known as Winter Time. Daylight Saving Time is also known as
|
18
|
+
# Advanced Time, Summer Time, or Legal Time in certain countries. The
|
19
|
+
# following table shows the changes in time zone rules in effect for
|
20
|
+
# New York City starting from 1967. Each line represents a description
|
21
|
+
# or rule for a particular observance.
|
22
|
+
class Timezone < Component
|
23
|
+
|
24
|
+
# Single properties
|
25
|
+
ical_property :dtstart, :start
|
26
|
+
ical_property :tzoffsetto, :timezone_offset_to
|
27
|
+
ical_property :tzoffsetfrom, :timezone_offset_from
|
28
|
+
|
29
|
+
# Multi-properties
|
30
|
+
ical_multi_property :comment, :comment, :comments
|
31
|
+
ical_multi_property :rdate, :recurrence_date, :recurrence_dates
|
32
|
+
ical_multi_property :rrule, :recurrence_rule, :recurrence_rules
|
33
|
+
|
34
|
+
def initialize()
|
35
|
+
super("VTIMEZONE")
|
36
|
+
@components = components
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_ical
|
40
|
+
super.to_s { |s| s << @components.each { |component| component.to_s } }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
module Icalendar
|
9
|
+
# A Todo calendar component is a grouping of component
|
10
|
+
# properties and possibly Alarm calendar components that represent
|
11
|
+
# an action-item or assignment. For example, it can be used to
|
12
|
+
# represent an item of work assigned to an individual; such as "turn in
|
13
|
+
# travel expense today".
|
14
|
+
class Todo < Component
|
15
|
+
attr_reader :alarms
|
16
|
+
|
17
|
+
# Single properties
|
18
|
+
ical_property :klass, nil, :class
|
19
|
+
ical_property :completed
|
20
|
+
ical_property :created
|
21
|
+
ical_property :description
|
22
|
+
ical_property :dtstamp, :timestamp
|
23
|
+
ical_property :dtstart, :start
|
24
|
+
ical_property :geo
|
25
|
+
ical_property :last_mod, :last_modification
|
26
|
+
ical_property :location
|
27
|
+
ical_property :organizer
|
28
|
+
ical_property :percent
|
29
|
+
ical_property :priority
|
30
|
+
ical_property :recurid, :recurrence_id
|
31
|
+
ical_property :seq, :sequence
|
32
|
+
ical_property :status
|
33
|
+
ical_property :summary
|
34
|
+
ical_property :uid, :user_id
|
35
|
+
ical_property :url
|
36
|
+
|
37
|
+
# Single but mutually exclusive TODO: not testing anything yet
|
38
|
+
ical_property :due
|
39
|
+
ical_property :duration
|
40
|
+
|
41
|
+
# Multi-properties
|
42
|
+
ical_multi_property :attach, :attachment, :attachments
|
43
|
+
ical_multi_property :attendee, :attendee, :attendees
|
44
|
+
ical_multi_property :categories, :category, :categories
|
45
|
+
ical_multi_property :comment, :comment, :comments
|
46
|
+
ical_multi_property :contact, :contact, :contacts
|
47
|
+
ical_multi_property :exdate, :exception_date, :exception_dates
|
48
|
+
ical_multi_property :exrule, :exception_rule, :exception_rules
|
49
|
+
ical_multi_property :rstatus, :request_status, :request_statuses
|
50
|
+
ical_multi_property :related_to, :related_to, :related_tos
|
51
|
+
ical_multi_property :resources, :resource, :resources
|
52
|
+
ical_multi_property :rdate, :recurrence_date, :recurrence_dates
|
53
|
+
ical_multi_property :rrule, :recurrence_rule, :recurrence_rules
|
54
|
+
|
55
|
+
def initialize()
|
56
|
+
super("VTODO")
|
57
|
+
|
58
|
+
@alarms = alarms
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_ical
|
62
|
+
print_string { |s| @alarms.each { |alarm| alarm.to_s } }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or modify it
|
5
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
6
|
+
details.
|
7
|
+
=end
|
8
|
+
|
9
|
+
require 'date'
|
10
|
+
|
11
|
+
### Add some to_ical methods to classes
|
12
|
+
|
13
|
+
# class Object
|
14
|
+
# def to_ical
|
15
|
+
# raise(NotImplementedError, "This object does not implement the to_ical method!")
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
|
19
|
+
class String
|
20
|
+
def to_ical
|
21
|
+
"#{self}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Fixnum
|
26
|
+
def to_ical
|
27
|
+
"#{self}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Float
|
32
|
+
def to_ical
|
33
|
+
"#{self}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Array
|
38
|
+
def to_ical
|
39
|
+
map{|elem| elem.to_ical}.join ','
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class DateTime < Date
|
44
|
+
def to_ical(utc = false)
|
45
|
+
s = ""
|
46
|
+
|
47
|
+
# 4 digit year
|
48
|
+
s << self.year.to_s
|
49
|
+
|
50
|
+
# Double digit month
|
51
|
+
s << "0" unless self.month > 9
|
52
|
+
s << self.month.to_s
|
53
|
+
|
54
|
+
# Double digit day
|
55
|
+
s << "0" unless self.day > 9
|
56
|
+
s << self.day.to_s
|
57
|
+
|
58
|
+
s << "T"
|
59
|
+
|
60
|
+
# Double digit hour
|
61
|
+
s << "0" unless self.hour > 9
|
62
|
+
s << self.hour.to_s
|
63
|
+
|
64
|
+
# Double digit minute
|
65
|
+
s << "0" unless self.min > 9
|
66
|
+
s << self.min.to_s
|
67
|
+
|
68
|
+
# Double digit second
|
69
|
+
s << "0" unless self.sec > 9
|
70
|
+
s << self.sec.to_s
|
71
|
+
|
72
|
+
# UTC time gets a Z suffix
|
73
|
+
if utc
|
74
|
+
s << "Z"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Date
|
80
|
+
def to_ical(utc = false)
|
81
|
+
s = ""
|
82
|
+
|
83
|
+
# 4 digit year
|
84
|
+
s << self.year.to_s
|
85
|
+
|
86
|
+
# Double digit month
|
87
|
+
s << "0" unless self.month > 9
|
88
|
+
s << self.month.to_s
|
89
|
+
|
90
|
+
# Double digit day
|
91
|
+
s << "0" unless self.day > 9
|
92
|
+
s << self.day.to_s
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Time
|
97
|
+
def to_ical(utc = false)
|
98
|
+
# Double digit hour
|
99
|
+
s << "0" unless self.hour > 9
|
100
|
+
s << self.hour.to_s
|
101
|
+
|
102
|
+
# Double digit minute
|
103
|
+
s << "0" unless self.min > 9
|
104
|
+
s << self.min.to_s
|
105
|
+
|
106
|
+
# Double digit second
|
107
|
+
s << "0" unless self.sec > 9
|
108
|
+
s << self.sec.to_s
|
109
|
+
|
110
|
+
# UTC time gets a Z suffix
|
111
|
+
if utc
|
112
|
+
s << "Z"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2005 Jeff Rose
|
3
|
+
Copyright (C) 2005 Sam Roberts
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or modify it
|
6
|
+
under the same terms as the ruby language itself, see the file COPYING for
|
7
|
+
details.
|
8
|
+
=end
|
9
|
+
|
10
|
+
module Icalendar
|
11
|
+
module DateProp
|
12
|
+
# date = date-fullyear date-month date-mday
|
13
|
+
# date-fullyear = 4 DIGIT
|
14
|
+
# date-month = 2 DIGIT
|
15
|
+
# date-mday = 2 DIGIT
|
16
|
+
DATE = '(\d\d\d\d)(\d\d)(\d\d)'
|
17
|
+
|
18
|
+
# time = time-hour [":"] time-minute [":"] time-second [time-secfrac] [time-zone]
|
19
|
+
# time-hour = 2 DIGIT
|
20
|
+
# time-minute = 2 DIGIT
|
21
|
+
# time-second = 2 DIGIT
|
22
|
+
# time-secfrac = "," 1*DIGIT
|
23
|
+
# time-zone = "Z" / time-numzone
|
24
|
+
# time-numzome = sign time-hour [":"] time-minute
|
25
|
+
# TIME = '(\d\d)(\d\d)(\d\d)(Z)?'
|
26
|
+
TIME = '(\d\d)(\d\d)(\d\d)'
|
27
|
+
|
28
|
+
# This method is called automatically when the module is mixed in.
|
29
|
+
# I guess you have to do this to mixin class methods rather than instance methods.
|
30
|
+
def self.append_features(base)
|
31
|
+
super
|
32
|
+
klass.extend(ClassMethods)
|
33
|
+
end
|
34
|
+
|
35
|
+
# This is made a sub-module just so it can be added as class
|
36
|
+
# methods rather than instance methods.
|
37
|
+
module ClassMethods
|
38
|
+
def date_property(dp, alias_name = nil)
|
39
|
+
dp = "#{dp}".strip.downcase
|
40
|
+
getter = dp
|
41
|
+
setter = "#{dp}="
|
42
|
+
query = "#{dp}?"
|
43
|
+
|
44
|
+
unless instance_methods.include? getter
|
45
|
+
code = <<-code
|
46
|
+
def #{getter}(*a)
|
47
|
+
if a.empty?
|
48
|
+
@properties[#{dp.upcase}]
|
49
|
+
else
|
50
|
+
self.#{dp} = a.first
|
51
|
+
end
|
52
|
+
end
|
53
|
+
code
|
54
|
+
|
55
|
+
module_eval code
|
56
|
+
end
|
57
|
+
|
58
|
+
unless instance_methods.include? setter
|
59
|
+
code = <<-code
|
60
|
+
def #{setter} a
|
61
|
+
@properties[#{dp.upcase}] = a
|
62
|
+
end
|
63
|
+
code
|
64
|
+
|
65
|
+
module_eval code
|
66
|
+
end
|
67
|
+
|
68
|
+
unless instance_methods.include? query
|
69
|
+
code = <<-code
|
70
|
+
def #{query}
|
71
|
+
@properties.has_key?(#{dp.upcase})
|
72
|
+
end
|
73
|
+
code
|
74
|
+
|
75
|
+
module_eval code
|
76
|
+
end
|
77
|
+
|
78
|
+
# Define the getter
|
79
|
+
getter = "get#{property.to_s.capitalize}"
|
80
|
+
define_method(getter.to_sym) do
|
81
|
+
puts "inside getting..."
|
82
|
+
getDateProperty(property.to_s.upcase)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Define the setter
|
86
|
+
setter = "set#{property.to_s.capitalize}"
|
87
|
+
define_method(setter.to_sym) do |*params|
|
88
|
+
date = params[0]
|
89
|
+
utc = params[1]
|
90
|
+
puts "inside setting..."
|
91
|
+
setDateProperty(property.to_s.upcase, date, utc)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Create aliases if a name was specified
|
95
|
+
# if not aliasName.nil?
|
96
|
+
# gasym = "get#{aliasName.to_s.capitalize}".to_sym
|
97
|
+
# gsym = getter.to_sym
|
98
|
+
# alias gasym gsym
|
99
|
+
|
100
|
+
# sasym = "set#{aliasName.to_s.capitalize}".to_sym
|
101
|
+
# ssym = setter.to_sym
|
102
|
+
# alias sasym ssym
|
103
|
+
# end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|