Class: Writexlsx::Package::SharedStrings

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/package/shared_strings.rb

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Method Summary collapse

Methods included from Utility

#absolute_char, delete_files, #put_deprecate_message, #substitute_cellref, #underline_attributes, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initializeSharedStrings

Returns a new instance of SharedStrings.



11
12
13
14
15
# File 'lib/write_xlsx/package/shared_strings.rb', line 11

def initialize
  @writer  = Package::XMLWriterSimple.new
  @strings = [] # string table
  @count   = {} # => count
end

Instance Method Details

#add(string) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/write_xlsx/package/shared_strings.rb', line 22

def add(string)
  str = string.dup
  if @count[str]
    @count[str] += 1
  else
    @strings << str
    @count[str] = 1
  end
end

#assemble_xml_fileObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/write_xlsx/package/shared_strings.rb', line 44

def assemble_xml_file
  write_xml_declaration

  # Write the sst table.
  write_sst

  # Write the sst strings.
  write_sst_strings

  # Close the sst tag.
  @writer.end_tag('sst')
  @writer.crlf
  @writer.close
end

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/write_xlsx/package/shared_strings.rb', line 36

def empty?
  @strings.empty?
end

#index(string) ⇒ Object



17
18
19
20
# File 'lib/write_xlsx/package/shared_strings.rb', line 17

def index(string)
  add(string)
  @strings.index(string)
end

#set_xml_writer(filename) ⇒ Object



40
41
42
# File 'lib/write_xlsx/package/shared_strings.rb', line 40

def set_xml_writer(filename)
  @writer.set_xml_writer(filename)
end

#string(index) ⇒ Object



32
33
34
# File 'lib/write_xlsx/package/shared_strings.rb', line 32

def string(index)
  @strings[index].dup
end