Sha256: 4111d599421ea5c960b8ec5eff7e3dbfd6365cdcfa7210b5780f7579d6b2544c

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require_relative 'number_formats/number_format'
module OoxmlParser
  # Parsing `numFmts` tag
  class NumberFormats < OOXMLDocumentObject
    # @return [Array, NumberFormat] array of number formats
    attr_accessor :number_formats_array

    def initialize(parent: nil)
      @number_formats_array = []
      @parent = parent
    end

    # Parse NumberFormats data
    # @param [Nokogiri::XML:Element] node with NumberFormats data
    # @return [NumberFormats] value of NumberFormats data
    def parse(node)
      node.attributes.each do |key, value|
        case key
        when 'count'
          @count = value.value.to_i
        end
      end

      node.xpath('*').each do |node_child|
        case node_child.name
        when 'numFmt'
          @number_formats_array << NumberFormat.new(parent: self).parse(node_child)
        end
      end
      self
    end

    # @param id [Integer] id of format
    # @return [NumberFormat, nil] value of format
    def format_by_id(id)
      @number_formats_array.each do |cur_format|
        return cur_format if cur_format.id == id
      end
      nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ooxml_parser-0.8.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.8.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.7.2 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.7.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.7.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.6.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.5.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb
ooxml_parser-0.5.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/number_formats.rb