merge_excel 0.2.1 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b4b332e7aeffcf25e4d60ba3da613d352671400
4
- data.tar.gz: 342ce48decad71444ff3a7c62f80d61e9d58d335
3
+ metadata.gz: e7d9194cae8de5e57f5b2c828ed06b84a8bcd64d
4
+ data.tar.gz: c23be5c9b741ad107636391285f2b90013040c38
5
5
  SHA512:
6
- metadata.gz: 55554b291704b54902b1f6302397f07d3657199335d802e9083d152dd0dda171be852401454bdc3184805bdaa65ff3aa79e11b4f1d09a88baf6a0985e67fb9e6
7
- data.tar.gz: 9463f8e58c96a1ca822a90f4f5265e1664b89bbe6d4c4608d3eec1dbf86f32c13ddb7e7fc798be0deb540fe6c30aa9ac5ece567647c8c1e4ea004237a85f2120
6
+ metadata.gz: 411b29d822d1dea25e569bfa1672f3c788e97562cb67c86a4d08b53635dd13c8a4e8eea954bd136b9a45ea70c26522e0395a5703e5bb89a445bc874c228ee1ac
7
+ data.tar.gz: 38d08dc4376f337ebf92276229b280c57803650a82379751bd771ff39e3188c61696fa1250fb81f9e8abe6bd8b7ba468526365ba5c4eea43f392924cc3ea080b
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
  /spec/results/
11
11
  /palestra.rb
12
12
  .byebug_history
13
+
14
+ *.gem
data/README.md CHANGED
@@ -22,6 +22,46 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ Given `excel_files_dir` the directory where the Excel files you want to merge are placed and `merged_file_path` the path or filename of the destination Excel file.
26
+
27
+
28
+ ```ruby
29
+ require 'merge_excel'
30
+
31
+ me = MergeExcel::Excel.new(excel_files_dir)
32
+ me.merge merged_file_path
33
+ ```
34
+ By default the command will merge:
35
+ - all worksheets
36
+ - the header line (first row)
37
+ - all rows until an empty one
38
+ - all columns
39
+
40
+ ### Options
41
+
42
+ Options allows you to control what to merge.
43
+
44
+ ```ruby
45
+ options = {
46
+ selector_pattern: "*.xls",
47
+ sheets_idxs: [1],
48
+ data_rows: {
49
+ 1 => {
50
+ header_row: 0, # or :missing
51
+ data_starting_row: 1,
52
+ data_first_column: 0,
53
+ data_last_column: 5 # omit or :last to get all columns
54
+ }
55
+ }
56
+ }
57
+
58
+ me = MergeExcel::Excel.new(excel_files_dir, options)
59
+ me.merge merged_file_path
60
+ ```
61
+
62
+ In this example will be merged only '.xls' files, of which only the columns from 0 to 5 of the second sheet.
63
+
64
+
25
65
 
26
66
 
27
67
  ## Development
@@ -2,18 +2,18 @@ module MergeExcel
2
2
  class Excel
3
3
  attr_reader :files
4
4
 
5
- def initialize(hash, selector_pattern="*.{xls,xlsx}")
6
- @settings = Settings::Parser.new(hash)
7
- @files = Dir.glob(File.join(@settings.input_dir, selector_pattern))
5
+ def initialize(input_dir, options={})
6
+ @settings = Settings::Parser.new(options)
7
+ @files = Dir.glob(File.join(input_dir, @settings.selector_pattern))
8
8
  end
9
9
 
10
- def merge
10
+ def merge(output_file_path)
11
11
  wbook = WBook.new(@settings)
12
12
  @files.each do |i_xls_filepath|
13
13
  puts i_xls_filepath
14
14
  wbook.import_data(i_xls_filepath)
15
15
  end
16
- wbook.export @settings.output_file_path
16
+ wbook.export output_file_path
17
17
  end
18
18
  end
19
19
  end
@@ -1,10 +1,9 @@
1
1
  module MergeExcel
2
2
  module Settings
3
3
  class Parser
4
- attr_reader :input_dir, :output_file_path, :sheets_idxs, :data_rows, :extra_data_rows
4
+ attr_reader :selector_pattern, :sheets_idxs, :data_rows, :extra_data_rows
5
5
  def initialize(hash)
6
- @input_dir = hash.fetch(:input_dir)
7
- @output_file_path = hash.fetch(:output_file_path)
6
+ @selector_pattern = hash.fetch(:selector_pattern){ "*.{xls,xlsx}" }
8
7
  read_sheets_index hash.fetch(:sheets_idxs){ :all }
9
8
  read_data_rows hash.fetch(:data_rows){ {any: DataRow::DEFAULT_DATA_ROW_CONFIG } }
10
9
  read_extra_data_rows hash.fetch(:extra_data_rows){ {any: ExtraDataRow::DEFAULT_EXTRA_DATA_ROW_CONFIG } }
@@ -1,3 +1,3 @@
1
1
  module MergeExcel
2
- VERSION = "0.2.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merge_excel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iwan Buetti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-06 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler