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, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initializeSharedStrings


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
# File 'lib/write_xlsx/package/shared_strings.rb', line 44

def assemble_xml_file
  write_xml_declaration do
    # Write the sst table.
    write_sst { write_sst_strings }
  end
end

#empty?Boolean


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

def empty?
  @strings.empty?
end

#index(string, params = {}) ⇒ Object


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

def index(string, params = {})
  add(string) unless params[:only_query]
  @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