File: text.rb

package info (click to toggle)
mhc 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,452 kB
  • sloc: ruby: 12,700; lisp: 7,577; makefile: 70; sh: 68
file content (44 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download | duplicates (4)
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
module RiCal
  class PropertyValue
    #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
    #
    # RiCal::PropertyValue::Text represents an icalendar Text property value
    # which is defined in 
    # rfc 2445 section 4.3.11 pp 45-46
    class Text < PropertyValue
      
      # Return the string value of the receiver
      def ruby_value
        if value
          value.gsub(/\\[;,nN\\]/) {|match|
            case match[1,1]
            when /[,;\\]/
              match[1,1]
            when 'n', 'N'
              "\n"
            else
              match
            end
          }
        else
          nil
        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)
            '\\n'
          else
            "\\#{match}"
          end
          }
        self.new(parent, :value => ical_str)
      end
    end
  end
end