-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues/50 from ical #226
Closed
Closed
Issues/50 from ical #226
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
7ea22dc
add first (basic) tests for from_ical parse
skyporter 6e22edb
add ruby mine settings to gitignore
skyporter 1e60567
add some tests
skyporter 0d47f2b
add netbeans folder to gitignore
jgauby 08edfef
adding method from_ical for import ical rrules
jgauby 144d6d8
file .gem
jgauby 0624cbc
gem 0.7.5
jgauby a2ee250
version 0.7.7
jgauby ecc2e7c
Merge branch 'master' of https://github.com/seejohnrun/ice_cube
skyporter 9a93eed
bump version
skyporter 4f1fd27
bump version
skyporter d6bd6c7
Fix ZeroDivisionError when INTERVAL is zero
jgauby 0d224b5
increment version
jgauby b337513
Merge remote-tracking branch 'digITpro/master'
btucker 0bf72cc
travis config
btucker aea04f5
travis stuff
btucker b7a6cc2
Merge branch 'master' of git://github.com/seejohnrun/ice_cube
btucker eb033d3
Add support for parsing ICAL format
btucker 9fa61d7
changed gemspec to have dev dependency on activesupport 4+
spra85 fa08a15
adding .bundle to gitignore
spra85 0c01b3e
removing deprecation warnings for using double instead of stub
spra85 111e91d
moved self.from_ical on Schedule and Rule into separate IcalParser class
spra85 d1d3651
added more descriptive text for test
spra85 c6d8584
add first (basic) tests for from_ical parse
skyporter fe69b40
resolving .gitignore conflicts
spra85 96bbbca
add some tests
skyporter 83e8b07
rebase
spra85 4700f8a
adding method from_ical for import ical rrules
jgauby 906bbee
file .gem
jgauby db9a435
gem 0.7.5
jgauby b7ce530
bump version
skyporter dfbf4fd
bump version
skyporter 8f52160
Fix ZeroDivisionError when INTERVAL is zero
jgauby 733fda8
travis config
btucker 18c950a
rebasing
spra85 be82268
fixing issues post rebase
spra85 1db5593
rebasin'
spra85 b26b437
changed gemspec to have dev dependency on activesupport 4+
spra85 a380de8
rebasin'
spra85 4d0cdd2
resolving rebase issues
spra85 c4b1572
added more descriptive text for test
spra85 96d6779
resolving merge conflicts
spra85 ce15cd1
removing dup from_ical methods on Rule missed in rebase
spra85 a53af38
tabs -> spaces
spra85 d054d92
tabs -> spaces
spra85 85d524c
moved IcalParser into parsers directory
spra85 7bf3f18
fixing indentation
spra85 70c4ad0
updating from_ical to not use deprecated hash key of start_date, usin…
spra85 6d4316f
Raising exception per feedback on pull request instead of a string so…
spra85 6b3007f
Added no-op for BYSETPOS in iCal.
uris77 0000d48
Removed comments
uris77 6e24f72
Merge pull request #2 from uris77/issues/bysetpos-in_ical
spra85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ coverage | |
coverage.data | ||
*.gem | ||
.bundle | ||
*.idea | ||
/nbproject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ notifications: | |
branches: | ||
only: | ||
- master | ||
- v0.7 | ||
- issues/50-from_ical | ||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module IceCube | ||
|
||
# An exception for when interval is set to zero | ||
class ZeroInterval < Exception | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module IceCube | ||
class IcalParser | ||
def self.schedule_from_ical(ical_string, options = {}) | ||
data = {} | ||
ical_string.each_line do |line| | ||
(property, value) = line.split(':') | ||
(property, tzid) = property.split(';') | ||
case property | ||
when 'DTSTART' | ||
data[:start_time] = Time.parse(value) | ||
when 'DTEND' | ||
data[:end_time] = Time.parse(value) | ||
when 'EXDATE' | ||
data[:extimes] ||= [] | ||
data[:extimes] += value.split(',').map{|v| Time.parse(v)} | ||
when 'DURATION' | ||
data[:duration] # FIXME | ||
when 'RRULE' | ||
data[:rrules] = [rule_from_ical(value)] | ||
end | ||
end | ||
Schedule.from_hash data | ||
end | ||
|
||
def self.rule_from_ical(ical) | ||
params = { validations: { } } | ||
|
||
ical.split(';').each do |rule| | ||
(name, value) = rule.split('=') | ||
value.strip! | ||
case name | ||
when 'FREQ' | ||
params[:freq] = value.downcase | ||
when 'INTERVAL' | ||
params[:interval] = value.to_i | ||
when 'COUNT' | ||
params[:count] = value.to_i | ||
when 'UNTIL' | ||
params[:until] = DateTime.parse(value).to_time.utc | ||
when 'WKST' | ||
params[:wkst] = TimeUtil.ical_day_to_symbol(value) | ||
when 'BYSECOND' | ||
params[:validations][:second_of_minute] = value.split(',').collect{ |v| v.to_i } | ||
when "BYMINUTE" | ||
params[:validations][:minute_of_hour] = value.split(',').collect{ |v| v.to_i } | ||
when "BYHOUR" | ||
params[:validations][:hour_of_day] = value.split(',').collect{ |v| v.to_i } | ||
when "BYDAY" | ||
dows = {} | ||
days = [] | ||
value.split(',').each do |expr| | ||
day = TimeUtil.ical_day_to_symbol(expr.strip[-2..-1]) | ||
if expr.strip.length > 2 # day with occurence | ||
occ = expr[0..-3].to_i | ||
dows[day].nil? ? dows[day] = [occ] : dows[day].push(occ) | ||
days.delete(TimeUtil.sym_to_wday(day)) | ||
else | ||
days.push TimeUtil.sym_to_wday(day) if dows[day].nil? | ||
end | ||
end | ||
params[:validations][:day_of_week] = dows unless dows.empty? | ||
params[:validations][:day] = days unless days.empty? | ||
when "BYMONTHDAY" | ||
params[:validations][:day_of_month] = value.split(',').collect{ |v| v.to_i } | ||
when "BYMONTH" | ||
params[:validations][:month_of_year] = value.split(',').collect{ |v| v.to_i } | ||
when "BYYEARDAY" | ||
params[:validations][:day_of_year] = value.split(',').collect{ |v| v.to_i } | ||
else | ||
raise "Invalid or unsupported rrule command : #{name}" | ||
end | ||
end | ||
|
||
params[:interval] ||= 1 | ||
# WKST only valid for weekly rules | ||
params.delete(:wkst) unless params[:freq] == 'weekly' | ||
|
||
rule = Rule.send(*params.values_at(:freq, :interval, :wkst).compact) | ||
rule.count(params[:count]) if params[:count] | ||
rule.until(params[:until]) if params[:until] | ||
params[:validations].each do |key, value| | ||
value.is_a?(Array) ? rule.send(key, *value) : rule.send(key, value) | ||
end | ||
|
||
rule | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to class these exceptions to they're easier to rescue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed up a change, thanks for the feedback @btucker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!!