class ExtractNamedReferences

Attributes

named_references[RW]
state[RW]

Public Class Methods

extract(input) click to toggle source
# File src/extract/extract_named_references.rb, line 8
def self.extract(input)
  self.new.extract(input)
end

Public Instance Methods

attr(name, value) click to toggle source
# File src/extract/extract_named_references.rb, line 33
def attr(name, value)
  case state
  when :parsing_sheet_name
    @sheet_names << value if name == :name
  when :parsing_named_reference
    @localSheetId = value.to_i if name == :localSheetId
    @name = value.downcase.to_sym if name == :name
  end
end
end_element(name) click to toggle source
# File src/extract/extract_named_references.rb, line 43
def end_element(name)
  case name
  when :sheet
    @state = :not_parsing
  when :definedName
    @state = :not_parsing

    reference = @reference.join.gsub('$','')

    @named_references[key] = reference

    @localSheetId = nil
    @name = nil
    @reference = []
  end
end
extract(input_xml) click to toggle source
# File src/extract/extract_named_references.rb, line 12
def extract(input_xml)
  @state = :not_parsing
  @sheet_names = [] # This keeps track of the sheet names
  @named_references = {}
  @localSheetId = nil
  @name = nil
  @reference = []
  Ox.sax_parse(self, input_xml, :convert_special => true)
  @named_references
end
key() click to toggle source
# File src/extract/extract_named_references.rb, line 66
def key
  return @name unless @localSheetId
  sheet = @sheet_names[@localSheetId].downcase.to_sym
  [sheet, @name]
end
start_element(name) click to toggle source
# File src/extract/extract_named_references.rb, line 23
def start_element(name)
  case name
  when :sheet
    @state = :parsing_sheet_name
  when :definedName
    @state = :parsing_named_reference
  end
end
text(text) click to toggle source
# File src/extract/extract_named_references.rb, line 60
def text(text)
  return unless state == :parsing_named_reference
  @reference << text
end