Class: ChupaText::Decomposers::OpenDocument::AttributesListener

Inherits:
SAXListener
  • Object
show all
Defined in:
lib/chupa-text/decomposers/opendocument.rb

Constant Summary collapse

META_URI =
"urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
DUBLIN_CORE_URI =
"http://purl.org/dc/elements/1.1/"

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ AttributesListener

Returns a new instance of AttributesListener.



76
77
78
79
80
# File 'lib/chupa-text/decomposers/opendocument.rb', line 76

def initialize(attributes)
  @attributes = attributes
  @name = nil
  @type = nil
end

Instance Method Details

#cdata(content) ⇒ Object



115
116
117
# File 'lib/chupa-text/decomposers/opendocument.rb', line 115

def cdata(content)
  set_attribute(content)
end

#characters(text) ⇒ Object



111
112
113
# File 'lib/chupa-text/decomposers/opendocument.rb', line 111

def characters(text)
  set_attribute(text)
end

#end_element(uri, local_name, qname) ⇒ Object



106
107
108
109
# File 'lib/chupa-text/decomposers/opendocument.rb', line 106

def end_element(uri, local_name, qname)
  @name = nil
  @type = nil
end

#set_attribute(value) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/chupa-text/decomposers/opendocument.rb', line 119

def set_attribute(value)
  return if @name.nil?

  case @type
  when :w3cdtf
    value = Time.xmlschema(value)
  when :array
    values = @attributes[@name] || []
    values << value
    value = values
  end
  @attributes[@name] = value
end

#start_element(uri, local_name, qname, attributes) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/chupa-text/decomposers/opendocument.rb', line 82

def start_element(uri, local_name, qname, attributes)
  case uri
  when META_URI
    case local_name
    when "creation-date"
      @name = "created_time"
      @type = :w3cdtf
    when "keyword"
      @name = "keywords"
      @type = :array
    when "generator"
      @name = local_name
    end
  when DUBLIN_CORE_URI
    case local_name
    when "date"
      @name = "modified_time"
      @type = :w3cdtf
    when "description", "title", "subject"
      @name = local_name
    end
  end
end