Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix x property access

  • Loading branch information...
commit e2a70d34149be90761b60019a4b6d747f14e8048 1 parent 55fbed2
@rubyredrick authored
View
6 Rakefile
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake'
+# require 'jeweler'
begin
require 'ad_agency'
@@ -27,8 +28,9 @@ A Google group for discussion of this library has been set up http://groups.goog
end
Jeweler::GemcutterTasks.new
Jeweler::AdAgencyTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+# rescue LoadError => ex
+# puts ex
+# puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
require 'rake/testtask'
View
13 lib/ri_cal/component.rb
@@ -155,17 +155,20 @@ def x_properties
end
# Add a n extended property
- def add_x_property(name, prop)
- x_properties[name] << prop
+ def add_x_property(name, prop, debug=false)
+ x_properties[name.gsub("_","-").upcase] << prop.to_ri_cal_text_property
end
def method_missing(selector, *args, &b) #:nodoc:
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] == "="
- add_x_property("x_#{match[1]}", *args)
+ args.each do |val|
+ add_x_property(x_property_key, val)
+ end
else
- x_properties[xprop_candidate]
+ x_properties[x_property_key].map {|property| property.value}
end
else
super
View
9 lib/ri_cal/core_extensions/date/conversions.rb
@@ -31,13 +31,14 @@ def to_overlap_range_end
to_ri_cal_date_time_value.end_of_day.to_datetime
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.
# In this case, it simply returns +self+.
def to_date
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
# and UTC offset is set to 0.
#
@@ -47,7 +48,7 @@ def to_date
# date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
def to_datetime
::DateTime.civil(year, month, day, 0, 0, 0, 0)
- end if RUBY_VERSION < '1.9'
+ end
end
end
end
View
5 lib/ri_cal/core_extensions/date_time/conversions.rb
@@ -32,12 +32,13 @@ def with_floating_timezone
dup.set_tzid(:floating)
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
def to_date
::Date.new(year, month, day)
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
def to_datetime
self
View
4 lib/ri_cal/core_extensions/string/conversions.rb
@@ -5,6 +5,10 @@ module String #:nodoc:
#- All rights reserved. Refer to the file README.txt for the license
#
module Conversions #:nodoc:
+ def to_ri_cal_text_property
+ PropertyValue::Text.new(nil, :value => self)
+ end
+
# Parse the receiver as an RiCal::PropertyValue::DateTime
def to_ri_cal_date_time_value(timezone_finder = nil)
params, value = *Parser.params_and_value(self, :no_leading_semicolon)
View
2  lib/ri_cal/core_extensions/time/conversions.rb
@@ -32,7 +32,7 @@ def with_floating_timezone
dup.set_tzid(:floating)
end
- unless defined? ActiveSupport
+ unless Time.instance_methods.map {|selector| selector.to_sym}.include?(:to_datetime)
require 'date'
::Time.send(:public, :to_datetime)
end
View
4 lib/ri_cal/property_value/text.rb
@@ -25,6 +25,10 @@ def ruby_value
end
end
+ def to_ri_cal_text_property
+ self
+ end
+
def self.convert(parent, string) #:nodoc:
ical_str = string.gsub(/\n\r?|\r\n?|,|;|\\/) {|match|
if ["\n", "\r", "\n\r", "\r\n"].include?(match)
View
13 spec/ri_cal/bugreports_spec.rb
@@ -260,4 +260,17 @@
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
View
2  spec/ri_cal/component_spec.rb
@@ -174,7 +174,7 @@
before(:each) 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
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."
Please sign in to comment.
Something went wrong with that request. Please try again.