File: extractor.rb

package info (click to toggle)
ruby-roo 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,216 kB
  • sloc: ruby: 6,529; xml: 88; makefile: 6
file content (39 lines) | stat: -rwxr-xr-x 742 bytes parent folder | download | duplicates (5)
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