aboutsummaryrefslogtreecommitdiffstats
path: root/lib/roo/excelx/extractor.rb
blob: b87a84edbb696eec993dd77a679265bfafc9e9df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require "roo/helpers/weak_instance_cache"

module Roo
  class Excelx
    class Extractor
      include Roo::Helpers::WeakInstanceCache

      COMMON_STRINGS = {
        t: "t",
        r: "r",
        s: "s",
        ref: "ref",
        html_tag_open: "<html>",
        html_tag_closed: "</html>"
      }

      def initialize(path, options = {})
        @path = path
        @options = options
      end

      private

      def doc
        instance_cache(:@doc) do
          raise FileNotFound, "#{@path} file not found" unless doc_exists?

          ::Roo::Utils.load_xml(@path).remove_namespaces!
        end
      end

      def doc_exists?
        @path && File.exist?(@path)
      end
    end
  end
end