Class: ChupaText::Decomposers::OfficeOpenXML::AttributesListener

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

Constant Summary collapse

CORE_PROPERTIES_URI =
"http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
EXTENDED_PROPERTIES_URI =
"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
DUBLIN_CORE_URI =
"http://purl.org/dc/elements/1.1/"
DUBLIN_CORE_TERMS_URI =
"http://purl.org/dc/terms/"

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ AttributesListener

Returns a new instance of AttributesListener.



178
179
180
181
182
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 178

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

Instance Method Details

#cdata(content) ⇒ Object



219
220
221
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 219

def cdata(content)
  set_attribute(content)
end

#characters(text) ⇒ Object



215
216
217
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 215

def characters(text)
  set_attribute(text)
end

#end_element(uri, local_name, qname) ⇒ Object



210
211
212
213
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 210

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

#set_attribute(value) ⇒ Object



223
224
225
226
227
228
229
230
231
232
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 223

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

  value = CGI.unescapeHTML(value)
  case @type
  when :w3cdtf
    value = Time.xmlschema(value)
  end
  @attributes[@name] = value
end

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



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 184

def start_element(uri, local_name, qname, attributes)
  case uri
  when CORE_PROPERTIES_URI
    case local_name
    when "keywords"
      @name = local_name
    end
  when EXTENDED_PROPERTIES_URI
    case local_name
    when "Application"
      @name = local_name.downcase
    end
  when DUBLIN_CORE_URI
    case local_name
    when "description", "title", "subject"
      @name = local_name
    end
  when DUBLIN_CORE_TERMS_URI
    case local_name
    when "created", "modified"
      @name = "#{local_name}_time"
      @type = :w3cdtf
    end
  end
end