Skip to content

Commit

Permalink
fix x property access
Browse files Browse the repository at this point in the history
  • Loading branch information
rubyredrick committed Feb 13, 2011
1 parent 55fbed2 commit e2a70d3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Rakefile
@@ -1,5 +1,6 @@
require 'rubygems' require 'rubygems'
require 'rake' require 'rake'
# require 'jeweler'


begin begin
require 'ad_agency' require 'ad_agency'
Expand Down Expand Up @@ -27,8 +28,9 @@ A Google group for discussion of this library has been set up http://groups.goog
end end
Jeweler::GemcutterTasks.new Jeweler::GemcutterTasks.new
Jeweler::AdAgencyTasks.new Jeweler::AdAgencyTasks.new
rescue LoadError # rescue LoadError => ex
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" # puts ex
# puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end end


require 'rake/testtask' require 'rake/testtask'
Expand Down
13 changes: 8 additions & 5 deletions lib/ri_cal/component.rb
Expand Up @@ -155,17 +155,20 @@ def x_properties
end end


# Add a n extended property # Add a n extended property
def add_x_property(name, prop) def add_x_property(name, prop, debug=false)
x_properties[name] << prop x_properties[name.gsub("_","-").upcase] << prop.to_ri_cal_text_property
end end


def method_missing(selector, *args, &b) #:nodoc: def method_missing(selector, *args, &b) #:nodoc:
xprop_candidate = selector.to_s xprop_candidate = selector.to_s
if (match = /^x_(.+)(=?)$/.match(xprop_candidate)) if (match = /^(x_.+)(=?)$/.match(xprop_candidate))
x_property_key = match[1].gsub('_','-').upcase
if match[2] == "=" if match[2] == "="
add_x_property("x_#{match[1]}", *args) args.each do |val|
add_x_property(x_property_key, val)
end
else else
x_properties[xprop_candidate] x_properties[x_property_key].map {|property| property.value}
end end
else else
super super
Expand Down
9 changes: 5 additions & 4 deletions lib/ri_cal/core_extensions/date/conversions.rb
Expand Up @@ -31,13 +31,14 @@ def to_overlap_range_end
to_ri_cal_date_time_value.end_of_day.to_datetime to_ri_cal_date_time_value.end_of_day.to_datetime
end end


unless defined? ActiveSupport unless Date.instance_methods.map {|selector| selector.to_sym}.include?(:to_date)
# A method to keep Time, Date and DateTime instances interchangeable on conversions. # A method to keep Time, Date and DateTime instances interchangeable on conversions.
# In this case, it simply returns +self+. # In this case, it simply returns +self+.
def to_date def to_date
self self
end if RUBY_VERSION < '1.9' end

end
unless Date.instance_methods.map {|selector| selector.to_sym}.include?(:to_datetime)
# Converts a Date instance to a DateTime, where the time is set to the beginning of the day # Converts a Date instance to a DateTime, where the time is set to the beginning of the day
# and UTC offset is set to 0. # and UTC offset is set to 0.
# #
Expand All @@ -47,7 +48,7 @@ def to_date
# date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000 # date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
def to_datetime def to_datetime
::DateTime.civil(year, month, day, 0, 0, 0, 0) ::DateTime.civil(year, month, day, 0, 0, 0, 0)
end if RUBY_VERSION < '1.9' end
end end
end end
end end
Expand Down
5 changes: 3 additions & 2 deletions lib/ri_cal/core_extensions/date_time/conversions.rb
Expand Up @@ -32,12 +32,13 @@ def with_floating_timezone
dup.set_tzid(:floating) dup.set_tzid(:floating)
end end


unless defined? ActiveSupport unless DateTime.instance_methods.map {|selector| selector.to_sym}.include?(:to_date)
# Converts self to a Ruby Date object; time portion is discarded # Converts self to a Ruby Date object; time portion is discarded
def to_date def to_date
::Date.new(year, month, day) ::Date.new(year, month, day)
end end

end
unless DateTime.instance_methods.map {|selector| selector.to_sym}.include?(:to_datetime)
# To be able to keep Times, Dates and DateTimes interchangeable on conversions # To be able to keep Times, Dates and DateTimes interchangeable on conversions
def to_datetime def to_datetime
self self
Expand Down
4 changes: 4 additions & 0 deletions lib/ri_cal/core_extensions/string/conversions.rb
Expand Up @@ -5,6 +5,10 @@ module String #:nodoc:
#- All rights reserved. Refer to the file README.txt for the license #- All rights reserved. Refer to the file README.txt for the license
# #
module Conversions #:nodoc: module Conversions #:nodoc:
def to_ri_cal_text_property
PropertyValue::Text.new(nil, :value => self)
end

# Parse the receiver as an RiCal::PropertyValue::DateTime # Parse the receiver as an RiCal::PropertyValue::DateTime
def to_ri_cal_date_time_value(timezone_finder = nil) def to_ri_cal_date_time_value(timezone_finder = nil)
params, value = *Parser.params_and_value(self, :no_leading_semicolon) params, value = *Parser.params_and_value(self, :no_leading_semicolon)
Expand Down
2 changes: 1 addition & 1 deletion lib/ri_cal/core_extensions/time/conversions.rb
Expand Up @@ -32,7 +32,7 @@ def with_floating_timezone
dup.set_tzid(:floating) dup.set_tzid(:floating)
end end


unless defined? ActiveSupport unless Time.instance_methods.map {|selector| selector.to_sym}.include?(:to_datetime)
require 'date' require 'date'
::Time.send(:public, :to_datetime) ::Time.send(:public, :to_datetime)
end end
Expand Down
4 changes: 4 additions & 0 deletions lib/ri_cal/property_value/text.rb
Expand Up @@ -25,6 +25,10 @@ def ruby_value
end end
end end


def to_ri_cal_text_property
self
end

def self.convert(parent, string) #:nodoc: def self.convert(parent, string) #:nodoc:
ical_str = string.gsub(/\n\r?|\r\n?|,|;|\\/) {|match| ical_str = string.gsub(/\n\r?|\r\n?|,|;|\\/) {|match|
if ["\n", "\r", "\n\r", "\r\n"].include?(match) if ["\n", "\r", "\n\r", "\r\n"].include?(match)
Expand Down
13 changes: 13 additions & 0 deletions spec/ri_cal/bugreports_spec.rb
Expand Up @@ -260,4 +260,17 @@
end end
end end


context "X-properties" do
it "should round-trip the X-WR-CALNAME property" do
cal_string = %Q(BEGIN:VCALENDAR
PRODID:-//Markthisdate.com\,0.7
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME: AFC Ajax Eredivisie wedstrijden 2010 - 2011
END:VCALENDAR)
cal = RiCal.parse_string(cal_string).first
cal.x_wr_calname.first.should == " AFC Ajax Eredivisie wedstrijden 2010 - 2011"
end
end


2 changes: 1 addition & 1 deletion spec/ri_cal/component_spec.rb
Expand Up @@ -174,7 +174,7 @@


before(:each) do before(:each) do
@it = RiCal.Calendar do @it = RiCal.Calendar do
add_x_property 'x_wr_calname', 'My Personal Calendar' add_x_property 'x_wr_calname', 'My Personal Calendar', true
event do event do
summary 'A Recurring Event' summary 'A Recurring Event'
description "This is some really long note content. It should be appropriately folded in the generated file.\nCarriage returns should work, too." description "This is some really long note content. It should be appropriately folded in the generated file.\nCarriage returns should work, too."
Expand Down

0 comments on commit e2a70d3

Please sign in to comment.