<commit_before>require_relative 'xlsx_cell/formula'
# Single Cell of XLSX
module OoxmlParser
  class XlsxCell < OOXMLDocumentObject
    attr_accessor :text, :formula, :character

    # @return [String] text without applying any style modificators, like quote_prefix
    attr_accessor :raw_text
    # @return [Integer] index of style
    attr_reader :style_index
    # @return [String] value of cell
    attr_reader :value
    # @return [String] type of string
    attr_reader :type

    def initialize(parent: nil)
      @style_index = 0 # default style is zero
      @text = ''
      @raw_text = ''
      @parent = parent
    end

    # Parse XlsxCell object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [XlsxCell] result of parsing
    def parse(node)
      if node.attribute('t')
        node.attribute('t').value == 's' ? get_shared_string(node.xpath('xmlns:v').text) : @raw_text = node.xpath('xmlns:v').text
      else
        @raw_text = node.xpath('xmlns:v').text
      end
      node.attributes.each do |key, value|
        case key
        when 's'
          @style_index = value.value.to_i
        when 't'
          @type = value.value.to_s
        end
      end
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'f'
          @formula = Formula.new(parent: self).parse(node_child)
        when 'v'
          @value = TextValue.new(parent: self).parse(node_child)
        end
      end
      @text = @raw_text.dup if @raw_text
      @text.insert(0, "'") if style.quote_prefix
      self
    end

    # @return [Xf] style of cell
    def style
      return nil unless @style_index
      root_object.style_sheet.cell_xfs.xf_array[@style_index]
    end

    private

    # Get shared string by it's number
    # @return [Nothing]
    def get_shared_string(value)
      return '' if value == ''
      string = root_object.shared_strings_table.string_indexes[value.to_i]<commit_msg>Redone more<commit_after>require_relative 'xlsx_cell/formula'
# Single Cell of XLSX
module OoxmlParser
  class XlsxCell < OOXMLDocumentObject
    attr_accessor :text, :formula, :character

    # @return [String] text without applying any style modificators, like quote_prefix
    attr_accessor :raw_text
    # @return [Integer] index of style
    attr_reader :style_index
    # @return [String] value of cell
    attr_reader :value
    # @return [String] type of string
    attr_reader :type

    def initialize(parent: nil)
      @style_index = 0 # default style is zero
      @text = ''
      @raw_text = ''
      @parent = parent
    end

    # Parse XlsxCell object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [XlsxCell] result of parsing
    def parse(node)
      node.attributes.each do |key, value|
        case key
        when 's'
          @style_index = value.value.to_i
        when 't'
          @type = value.value.to_s
        end
      end
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'f'
          @formula = Formula.new(parent: self).parse(node_child)
        when 'v'
          @value = TextValue.new(parent: self).parse(node_child)
        end
      end
      if @type && @value
        node.attribute('t').value == 's' ? get_shared_string(value.value) : @raw_text = value.value
      elsif @value
        @raw_text = value.value if @value
      end
      @text = @raw_text.dup if @raw_text
      @text.insert(0, "'") if style.quote_prefix
      self
    end

    # @return [Xf] style of cell
    def style
      return nil unless @style_index
      root_object.style_sheet.cell_xfs.xf_array[@style_index]
    end

    private

    # Get shared string by it's number
    # @return [Nothing]
    def get_shared_string(value)
      return '' if value == ''
      string = root_object.shared_strings_table.string_indexes[value.to_i]
{'fraction_non_alphanumeric': 0.10018120631633445, 'fraction_numerical': 0.0010354646647683149, 'mean_word_length': 2.4842200180342653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2658461', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1224, 'n_words': 324}