Class: RubyXL::SharedStringsTable

Inherits:
OOXMLTopLevelObject show all
Defined in:
lib/rubyXL/objects/shared_strings.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLTopLevelObject

#add_to_zip, #filepath, parse_file, set_namespaces

Methods included from OOXMLObjectClassMethods

#define_attribute, #define_child_node, #define_element_name, #obtain_class_variable, #parse, #set_countable

Methods included from OOXMLObjectInstanceMethods

#dup, #index_in_collection, #write_xml

Constructor Details

#initialize(*params) ⇒ SharedStringsTable

Returns a new instance of SharedStringsTable.



17
18
19
20
21
22
23
# File 'lib/rubyXL/objects/shared_strings.rb', line 17

def initialize(*params)
  super
  # So far, going by the structure that the original creator had in mind. However, 
  # since the actual implementation is now extracted into a separate class, 
  # we will be able to transparrently change it later if needs be.
  @index_by_content = {}
end

Class Method Details

.filepathObject



51
52
53
# File 'lib/rubyXL/objects/shared_strings.rb', line 51

def self.filepath
  File.join('xl', 'sharedStrings.xml')
end

Instance Method Details

#[](index) ⇒ Object



31
32
33
# File 'lib/rubyXL/objects/shared_strings.rb', line 31

def [](index)
  strings[index]
end

#add(str, index = nil) ⇒ Object



39
40
41
42
43
# File 'lib/rubyXL/objects/shared_strings.rb', line 39

def add(str, index = nil)
  index ||= strings.size
  strings[index] = RubyXL::Text.new(:value => str)
  @index_by_content[str] = index
end

#before_write_xmlObject



25
26
27
28
29
# File 'lib/rubyXL/objects/shared_strings.rb', line 25

def before_write_xml
  super
  self.unique_count = self.count
  self.count > 0
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rubyXL/objects/shared_strings.rb', line 35

def empty?
  strings.empty?
end

#get_index(str, add_if_missing = false) ⇒ Object



45
46
47
48
49
# File 'lib/rubyXL/objects/shared_strings.rb', line 45

def get_index(str, add_if_missing = false)
  index = @index_by_content[str]
  index = add(str) if index.nil? && add_if_missing
  index 
end