rxl 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +47 -15
- data/lib/cell.rb +0 -12
- data/lib/rxl/version.rb +1 -1
- data/lib/workbook.rb +0 -1
- data/lib/worksheet.rb +3 -10
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 423f052155f315079efc3acd473a98ba955f378571aeba1eee1706f99d30c8a3
|
4
|
+
data.tar.gz: bf910f39824c12a512b7fafdcd94a6d478d1fc64bcfdcaa26c5a45c2d5c4b8d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5489f6b1c8500457e0bb093b4437614c3ac3ecda3d28d9bae9c6f519817355217fa5e7701a33b331e34d18873ac4d38e3749110ddb4ab2cc23f33255eb70ac2e
|
7
|
+
data.tar.gz: dbab0226eb5a2e6bb82d5f345630f50d4f6da2bbdff5c96eeed154998821c228e5dab0610e9bbefbce2f6088f2daf09b171d343d98280843c4e7ff4909084576
|
data/README.md
CHANGED
@@ -101,6 +101,35 @@ The format of the excel table read hash has the following skeleton:
|
|
101
101
|
}
|
102
102
|
```
|
103
103
|
|
104
|
+
### Read multiple files at once
|
105
|
+
|
106
|
+
Pass a hash of filepaths to read, get a hash of file contents back.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
filepaths_hash = {
|
110
|
+
first_file: 'path/to/file.xlsx',
|
111
|
+
second_file: 'path/to/file.xlsx'
|
112
|
+
}
|
113
|
+
|
114
|
+
Rxl.read_files(filepaths_hash)
|
115
|
+
Rxl.read_files(filepaths_hash, :as_tables)
|
116
|
+
```
|
117
|
+
|
118
|
+
Returns the files with sheet contents populated with hash of cells (or array of rows if :as_tables read type is specified):
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
{
|
122
|
+
first_file: {
|
123
|
+
"Sheet1" => 'sheet_contents',
|
124
|
+
"Sheet2" => 'sheet_contents'
|
125
|
+
},
|
126
|
+
second_file: {
|
127
|
+
"Sheet1" => 'sheet_contents',
|
128
|
+
"Sheet2" => 'sheet_contents'
|
129
|
+
},
|
130
|
+
}
|
131
|
+
```
|
132
|
+
|
104
133
|
### Write to file
|
105
134
|
|
106
135
|
To write a file pass the filename and hash:
|
@@ -109,16 +138,13 @@ To write a file pass the filename and hash:
|
|
109
138
|
Rxl.write_file('path/to/save.xlsx', hash_workbook)
|
110
139
|
```
|
111
140
|
|
112
|
-
The format of the excel hash_workbook
|
141
|
+
The format of the excel hash_workbook has sheet names as keys and hashes of cells as values:
|
113
142
|
|
114
143
|
```ruby
|
115
144
|
{
|
116
145
|
"Sheet1" => {
|
117
|
-
|
118
|
-
'
|
119
|
-
value: 'abc',
|
120
|
-
format: 'text'
|
121
|
-
}
|
146
|
+
'A1' => {
|
147
|
+
value: 'abc'
|
122
148
|
}
|
123
149
|
}
|
124
150
|
}
|
@@ -150,21 +176,27 @@ The following rules are validated for write_file:
|
|
150
176
|
* The hash_workbook keys must be strings
|
151
177
|
* The hash_workbook values (hash_worksheet) must be hashes
|
152
178
|
|
153
|
-
|
154
|
-
* The hash_worksheet
|
155
|
-
* The following keys are allowed for hash_worksheet: :cells, :rows, :columns
|
156
|
-
* The hash_worksheet values must be arrays - those arrays must contain only hashes
|
157
|
-
|
158
|
-
|
159
|
-
* The arrays' child hash keys must be strings of valid Excel cell id format (or stringified number for a row, capitalised alpha for a column)
|
160
|
-
* The arrays' child hash values must be hashes (hash_cell)
|
179
|
+
* The hash_worksheet keys must be strings of valid Excel cell id format
|
180
|
+
* The hash_worksheet values must be hashes (specifying cells)
|
161
181
|
* The hash_cell keys must conform the the cell specification as below
|
162
182
|
|
163
183
|
* If a formula is provided the value must be nil or an empty string
|
164
184
|
* If a number format is provided the value must be consistent with it
|
165
185
|
|
166
186
|
|
167
|
-
|
187
|
+
Cells are specified as hashes following this example:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
{
|
191
|
+
value: 'abc'
|
192
|
+
}
|
193
|
+
```
|
194
|
+
|
195
|
+
Other keys can be specified:
|
196
|
+
* v_align: :top, :centre or :bottom (default)
|
197
|
+
* h_align: :left (default), :centre or :right
|
198
|
+
|
199
|
+
TODO: add full description for hash_cell_to_rubyxl_cell and rubyxl_cell_to_hash_cell (and check they're as consistent as possible)
|
168
200
|
|
169
201
|
## Development
|
170
202
|
|
data/lib/cell.rb
CHANGED
@@ -76,18 +76,6 @@ module Cell
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
def self.get_combined_hash_cell(hash_worksheet, hash_cell_key, hash_cell)
|
80
|
-
# first get data from the matching column if it's specified
|
81
|
-
column_keys = hash_worksheet[:columns].keys.select { |key| hash_cell_key =~ /^#{key}\d+$/ }
|
82
|
-
column_keys.empty? ? hash_column = {} : hash_column = hash_worksheet[:columns][column_keys[0]]
|
83
|
-
combined_hash_cell = hash_column.merge(hash_cell)
|
84
|
-
# then get data from the matching row if it's specified
|
85
|
-
row_keys = hash_worksheet[:rows].keys.select { |key| hash_cell_key =~ /^\D+#{key}$/ }
|
86
|
-
row_keys.empty? ? hash_row = {} : hash_row = hash_worksheet[:rows][row_keys[0]]
|
87
|
-
combined_hash_cell = hash_row.merge(combined_hash_cell)
|
88
|
-
hash_worksheet[:worksheet].merge(combined_hash_cell)
|
89
|
-
end
|
90
|
-
|
91
79
|
|
92
80
|
##################################
|
93
81
|
### VALIDATE HASH CELL ###
|
data/lib/rxl/version.rb
CHANGED
data/lib/workbook.rb
CHANGED
data/lib/worksheet.rb
CHANGED
@@ -26,11 +26,10 @@ module Worksheet
|
|
26
26
|
|
27
27
|
def self.hash_worksheet_to_rubyxl_worksheet(hash_worksheet, rubyxl_worksheet)
|
28
28
|
process_sheet_to_populated_block(hash_worksheet)
|
29
|
-
(hash_worksheet
|
30
|
-
combined_hash_cell = Cell.get_combined_hash_cell(hash_worksheet, hash_cell_key, hash_cell)
|
29
|
+
(hash_worksheet || {}).sort.each do |hash_cell_key, hash_cell|
|
31
30
|
row_index, column_index = RubyXL::Reference.ref2ind(hash_cell_key)
|
32
|
-
Cell.add_rubyxl_cells(
|
33
|
-
Cell.hash_cell_to_rubyxl_cell(
|
31
|
+
Cell.add_rubyxl_cells(hash_cell, rubyxl_worksheet, row_index, column_index)
|
32
|
+
Cell.hash_cell_to_rubyxl_cell(hash_cell, rubyxl_worksheet, row_index, column_index)
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
@@ -64,12 +63,6 @@ module Worksheet
|
|
64
63
|
### OTHER PUBLIC METHODS ###
|
65
64
|
####################################
|
66
65
|
|
67
|
-
def self.set_hash_worksheet_defaults(hash_worksheet)
|
68
|
-
%i[worksheet columns rows].each do |key|
|
69
|
-
hash_worksheet[key] = {} unless hash_worksheet.has_key?(key)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
66
|
def self.hash_worksheet_to_hash_table(raw_hash)
|
74
67
|
cells = Mitrush.deep_copy(raw_hash)
|
75
68
|
columns = cells.keys.map { |key| key[/\D+/] }.uniq
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rxl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian McWilliams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
|
116
|
-
rubygems_version: 2.7.7
|
115
|
+
rubygems_version: 3.0.2
|
117
116
|
signing_key:
|
118
117
|
specification_version: 4
|
119
118
|
summary: A ruby spreadsheet interface
|