File: conversions.rb

package info (click to toggle)
mhc 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,320 kB
  • ctags: 3,529
  • sloc: ruby: 12,404; lisp: 7,448; makefile: 70; sh: 69
file content (57 lines) | stat: -rw-r--r-- 2,545 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module RiCal
  module CoreExtensions #:nodoc:
    module String #:nodoc:
      #- ©2009 Rick DeNatale
      #- 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)
          if PropertyValue::DateTime.valid_string?(value)
             PropertyValue::DateTime.new(timezone_finder, :params => params, :value => value)
           else
             raise InvalidPropertyValue.new("#{self.inspect} is not a valid rfc 2445 date-time")
           end
        end
        

        def to_ri_cal_date_or_date_time_value(timezone_finder = nil)
          params, value = *Parser.params_and_value(self, :no_leading_semicolon)
          if PropertyValue::DateTime.valid_string?(value) || PropertyValue::Date.valid_string?(value)
            PropertyValue.date_or_date_time(timezone_finder, :params => params, :value => value)
          else
            raise InvalidPropertyValue.new("#{self.inspect} is not a valid rfc 2445 date or date-time")
          end
        end

        # Parse the receiver as an RiCal::PropertyValue::DurationValue
        def to_ri_cal_duration_value(timezone_finder = nil)
          params, value = *Parser.params_and_value(self)
          if PropertyValue::Duration.valid_string?(value)
            PropertyValue::Duration.new(timezone_finder, :params => params, :value => value)
          else
            raise InvalidPropertyValue.new("#{self.inspect} is not a valid rfc 2445 duration")
          end
        end

        def to_ri_cal_occurrence_list_value(timezone_finder = nil)
          params, value = *Parser.params_and_value(self, :no_leading_semicolon)
          if PropertyValue::DateTime.valid_string?(value)
            PropertyValue::DateTime.new(timezone_finder, :params => params, :value => value)
          elsif PropertyValue::Date.valid_string?(value)
            PropertyValue::Date.new(timezone_finder, :params => params, :value => value)
          elsif PropertyValue::Period.valid_string?(value)
            PropertyValue::Period.new(timezone_finder, :params => params, :value => value)
          else
            raise "Invalid value for occurrence list #{self.inspect}"
          end
        end
       end
    end
  end
end