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.



125
126
127
128
129
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 125

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

Instance Method Details

#cdata(content) ⇒ Object



166
167
168
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 166

def cdata(content)
  set_attribute(content)
end

#characters(text) ⇒ Object



162
163
164
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 162

def characters(text)
  set_attribute(text)
end

#end_element(uri, local_name, qname) ⇒ Object



157
158
159
160
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 157

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

#set_attribute(value) ⇒ Object



170
171
172
173
174
175
176
177
178
179
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 170

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



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 131

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