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.



64
65
66
67
68
69
70
71
# File 'lib/when_exe/parts/resource.rb', line 64

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.



59
60
61
# File 'lib/when_exe/parts/resource.rb', line 59

def attribute
  @attribute
end

#markedObject (readonly)

Returns the value of attribute marked.



62
63
64
# File 'lib/when_exe/parts/resource.rb', line 62

def marked
  @marked
end

#namespaceObject

Returns the value of attribute namespace.



60
61
62
# File 'lib/when_exe/parts/resource.rb', line 60

def namespace
  @namespace
end

#objectObject

Returns the value of attribute object.



58
59
60
# File 'lib/when_exe/parts/resource.rb', line 58

def object
  @object
end

#predicateObject (readonly)

Returns the value of attribute predicate.



57
58
59
# File 'lib/when_exe/parts/resource.rb', line 57

def predicate
  @predicate
end

#same_altidObject

Returns the value of attribute same_altid.



61
62
63
# File 'lib/when_exe/parts/resource.rb', line 61

def same_altid
  @same_altid
end

Class Method Details

.extract_rfc5545_Property(specification, options) ⇒ Object

行から RFC5545 の Property を取り出す



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/when_exe/parts/resource.rb', line 77

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