spreadsheet_erb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spreadsheet_erb.rb +15 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd6359c8c5a03ef4b0617e8397698eaaeed4ce06
4
- data.tar.gz: 9b5fe71a858de5f7bf81d377aaec3aac4250ae1f
3
+ metadata.gz: 01f255df12cc6aa3da68bf1bde835897312dbd46
4
+ data.tar.gz: f5e2820d8807faab9a54e70c871df80291ea2769
5
5
  SHA512:
6
- metadata.gz: 16908742b088b7394365aacabf2549ff498cdebba3f1cf1e0e915c07f93b8bd444ac82509357396107279fde75dc68e0bf21616ea224a99367c996a262048f70
7
- data.tar.gz: 281fd0c9b5ff63e1bf999b743d48962999ce5a11460cd27d59055974a34126018c5e60ba173e15781cb90c4ade90c2d8a3ab4e1fb2bc59afeabef6ae6fee7e81
6
+ metadata.gz: ea67b8db8b911f388291280e54e68b915ec5ea747c2305e9bc8d63fb934f7338fe7a89505e5a3e1133ef5d4d8be6347822c0cbbdb83ca8ab94fd51e4513c5b28
7
+ data.tar.gz: c3ef07231b9190b3e3e734d17e927c53c79b703cd5632f8d4928be462b92936a2511a9360531644e89b047380281eba5b2f9cd0beded7df87d7deae11cc3025e
@@ -4,29 +4,34 @@ require 'zip'
4
4
 
5
5
  class SpreadsheetErb
6
6
 
7
- def initialize(template_path:, context:, temp_path: './tmp')
8
- @template_path = template_path
7
+ def initialize(template_dir:, context:, temp_dir: Dir.mktmpdir)
8
+ @template_dir = template_dir
9
9
  @context = context
10
- @temp_path = temp_path
10
+ @temp_dir = temp_dir
11
11
  end
12
12
 
13
13
  def render
14
14
  copy_template()
15
- xml_paths = find_xml_paths(@temp_path)
15
+ xml_paths = find_xml_paths(@temp_dir)
16
16
  xml_paths.each do |xml_path|
17
17
  result = render_file(xml_path)
18
18
  save_file(xml_path, result)
19
19
  end
20
20
  end
21
21
 
22
- def write(result_path)
22
+ def write(result_path = "#{@temp_dir}/result-#{Time.now}.xlsx")
23
23
  File.delete(result_path) if File.exist?(result_path)
24
- zip("#{@temp_path}/template", result_path)
25
- remove_template()
24
+ zip("#{@temp_dir}/template", result_path)
25
+ get_file(result_path)
26
26
  end
27
27
 
28
+
28
29
  private
29
30
 
31
+ def get_file(file_path)
32
+ File.new(file_path, mode: 'r')
33
+ end
34
+
30
35
  def render_file(file_path)
31
36
  template = File.read(file_path)
32
37
  renderer = ERB.new(template)
@@ -38,16 +43,12 @@ class SpreadsheetErb
38
43
  File.write(file_path, value)
39
44
  end
40
45
 
41
- def find_xml_paths(template_path)
42
- Dir.glob("#{template_path}/**/*.xml")
46
+ def find_xml_paths(template_dir)
47
+ Dir.glob("#{template_dir}/**/*.xml")
43
48
  end
44
49
 
45
50
  def copy_template
46
- FileUtils.cp_r(@template_path, @temp_path)
47
- end
48
-
49
- def remove_template
50
- FileUtils.rm_r(Dir.glob("#{@temp_path}/*"))
51
+ FileUtils.cp_r(@template_dir, @temp_dir)
51
52
  end
52
53
 
53
54
  def zip(directory_to_zip, result_path)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Wierzbicki