Class: XlsxWriter::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/xlsx_writer/xml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Xml

Returns a new instance of Xml.



16
17
18
19
# File 'lib/xlsx_writer/xml.rb', line 16

def initialize(document)
  @mutex = Mutex.new
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



14
15
16
# File 'lib/xlsx_writer/xml.rb', line 14

def document
  @document
end

Class Method Details

.autoObject



7
8
9
10
11
# File 'lib/xlsx_writer/xml.rb', line 7

def auto
  descendants.reject do |klass|
    klass.const_defined?(:AUTO) and klass.const_get(:AUTO) == false
  end
end

Instance Method Details

#generateObject



21
22
23
24
# File 'lib/xlsx_writer/xml.rb', line 21

def generate
  path
  true
end

#generated?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/xlsx_writer/xml.rb', line 26

def generated?
  @generated == true
end

#pathObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/xlsx_writer/xml.rb', line 30

def path
  @path || @mutex.synchronize do
    @path ||= begin
      memo = ::File.join document.staging_dir, relative_path
      ::FileUtils.mkdir_p ::File.dirname(memo)
      ::File.open(memo, 'wb') do |f|
        f.write render
      end
      converted = ::UnixUtils.unix2dos memo
      ::FileUtils.mv converted, memo
      @generated = true
      memo
    end
  end
end

#renderObject



50
51
52
# File 'lib/xlsx_writer/xml.rb', line 50

def render
  ::ERB.new(::File.read(template_path), nil, '<>').result(binding)
end

#template_pathObject



46
47
48
# File 'lib/xlsx_writer/xml.rb', line 46

def template_path
  ::File.expand_path "../xml/#{self.class.name.demodulize.underscore}.erb", __FILE__
end