Class: ChupaText::Decomposers::OfficeOpenXML::SharedStringsListener

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

Instance Method Summary collapse

Constructor Details

#initialize(output, target_uri) ⇒ SharedStringsListener

Returns a new instance of SharedStringsListener.



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

def initialize(output, target_uri)
  @output = output
  @target_uri = target_uri
  @tag_stack = []
  @in_target = false
  @current_text = +""
end

Instance Method Details

#cdata(content) ⇒ Object



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

def cdata(content)
  @current_text << content if @in_target
end

#characters(text) ⇒ Object



154
155
156
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 154

def characters(text)
  @current_text << text if @in_target
end

#end_element(uri, local_name, qname) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 143

def end_element(uri, local_name, qname)
  return unless uri == @target_uri
  case local_name
  when "t"
    add_text(@current_text)
    @in_target = false
  end
ensure
  @tag_stack.pop
end

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



132
133
134
135
136
137
138
139
140
141
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 132

def start_element(uri, local_name, qname, attributes)
  @tag_stack << local_name

  return unless uri == @target_uri
  case local_name
  when "t"
    @in_target = true
    @current_text = +""
  end
end