Class: When::Parts::Resource::ContentLine

Inherits:
Object
  • Object
show all
Defined in:
lib/when_exe/parts/resource.rb

Constant Summary collapse

RFC6350 =
{
  "\\\\" => "\\",
  "\\n"  => "\n",
  "\\N"  => "\n",
  "\\;"  => ";",
  "\\:"  => ":"
}
RFC6868 =
{
  "^n"  => "\n",
  "^^"  => "^",
  "^'"  => '"'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, object = nil, marked = nil) ⇒ ContentLine

Returns a new instance of ContentLine.



76
77
78
79
80
81
82
83
# File 'lib/when_exe/parts/resource.rb', line 76

def initialize(key, object=nil, marked=nil)
  key = key.downcase.gsub(/-/,'_') if (key==key.upcase)
  @predicate, @namespace = key.split(/:/).reverse
  object     = object.gsub(/\^./) {|escape| RFC6868[escape] || escape} if object.instance_of?(String)
  @object    = object
  @marked    = marked
  @attribute = {}
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



71
72
73
# File 'lib/when_exe/parts/resource.rb', line 71

def attribute
  @attribute
end

#markedObject (readonly)

Returns the value of attribute marked.



74
75
76
# File 'lib/when_exe/parts/resource.rb', line 74

def marked
  @marked
end

#namespaceObject

Returns the value of attribute namespace.



72
73
74
# File 'lib/when_exe/parts/resource.rb', line 72

def namespace
  @namespace
end

#objectObject

Returns the value of attribute object.



70
71
72
# File 'lib/when_exe/parts/resource.rb', line 70

def object
  @object
end

#predicateObject (readonly)

Returns the value of attribute predicate.



69
70
71
# File 'lib/when_exe/parts/resource.rb', line 69

def predicate
  @predicate
end

#same_altidObject

Returns the value of attribute same_altid.



73
74
75
# File 'lib/when_exe/parts/resource.rb', line 73

def same_altid
  @same_altid
end

Class Method Details

.extract_rfc5545_Property(specification, options) ⇒ Object

行から RFC5545 の Property を取り出す



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/when_exe/parts/resource.rb', line 89

def self.extract_rfc5545_Property(specification, options)
  return specification unless specification =~ /\A[-A-Z_]+=.+?:/i
  caret = 0
  specification.length.times do |i|
    caret = specification[i..i] == '^' ? caret + 1 : 0
    if caret[0] == 0 && specification[i..i] == ':'
      specification[0...i].gsub(/\^./) {|escape| RFC6868[escape] || escape}.
        scan(/((?:[^\\;]|\\.)+)(?:;(?!\z))?|;/).flatten.each do |pr|
        pr ||= ''
        pr.gsub!(/\\./) {|escape| RFC6350[escape] || escape}
        key, value = pr.split(/=/, 2)
        case key
        when 'VALUE' ; options[:precision] = value
        when 'TZID'  ; options[:clock] = 
          case When::V::Timezone[value]
          when Array ; When::V::Timezone[value][-1]
          when nil   ; When::Parts::Timezone.new(value)
          else       ; When::V::Timezone[value]
          end
        else         ; options[key]    = value
        end
      end
      return specification[(i+1)..-1]
    end
  end
  return specification
end