fast_xls_to_hash 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 782db936290b05c435ca93b177a47c19666be143
4
- data.tar.gz: f19c6aeb08fb0df0e5bb2515126175b246c32de9
3
+ metadata.gz: 9423dca5cfc43f8e55b28bd1664ebdf574711ffd
4
+ data.tar.gz: 67ae3f7258d8221d773f5e4806296776305fa51d
5
5
  SHA512:
6
- metadata.gz: cb4ececc8c3f754d4c79a0706a3a5017d70e3e8c9264f72d9e71ae76633b75c988f2bf814a326aaa34c60cac5f6daca3e2f5484ee5096010ed7861f44f2791be
7
- data.tar.gz: 285fd283634f853822956f30f81ac27b67afe2812c7a00c7c99830f56b5cff67be3caffed2598a76064266b58d51b99c0210214ebee4324168809765a4afb99a
6
+ metadata.gz: 0dd21147fabe999f915ab4f784427cee9234b018c3a2823d0637c87ce6e6d728d2c611960a5dfecb34c2bd02cbd8adb5767bd1f877630cfd784119ca3d595b08
7
+ data.tar.gz: d339cd31726b4f0043eb7dda8474ecd7baa231e6f42afdc20b0a7ca96f39bdfae508ecd133213696268ffcebb2c0c9d12345fb53192b882902b661a8d3c2f5e4
@@ -1,5 +1,15 @@
1
1
  require "fast_xls_to_hash/version"
2
+ require "fast_xls_to_hash/convert_number_to_xls_column/number_to_xls_column"
2
3
  require "fast_xls_to_hash/xls/parse"
3
4
 
4
5
  module FastXlsToHash
6
+ @@xls_style = false
7
+
8
+ def self.with_xls_style=(bool)
9
+ @@xls_style = bool
10
+ end
11
+
12
+ def self.with_xls_style
13
+ @@xls_style
14
+ end
5
15
  end
@@ -0,0 +1,17 @@
1
+ module FastXlsToHash
2
+ class Converter
3
+ CHAR = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
4
+
5
+ def self.to_characters(num)
6
+ num += 1
7
+ result = ''
8
+ while(num > 0)
9
+ num -= 1
10
+ rest = num % 26
11
+ num = num / 26
12
+ result += CHAR[rest]
13
+ end
14
+ result.reverse
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module FastXlsToHash
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -8,8 +8,17 @@ module FastXlsToHash
8
8
 
9
9
  def self.to_hash(file)
10
10
  book = Spreadsheet.open(file)
11
-
12
11
  hash = Hash.new{ |hash, key| hash[key] = {} }
12
+ FastXlsToHash.with_xls_style ? with_characters(book, hash) : without_characters(book, hash)
13
+
14
+ kill(book)
15
+
16
+ hash
17
+ end
18
+
19
+ private
20
+
21
+ def self.without_characters(book, hash)
13
22
  book.worksheets.each do |sheet|
14
23
  sheet.each_with_index do |row, row_index|
15
24
  hash[sheet.name.to_sym]["row_#{row_index + 1}".to_sym] = {}
@@ -26,13 +35,26 @@ module FastXlsToHash
26
35
  end
27
36
  end
28
37
  end
29
-
30
- kill(book)
31
-
32
- hash
33
38
  end
34
39
 
35
- private
40
+ def self.with_characters(book, hash)
41
+ book.worksheets.each do |sheet|
42
+ sheet.each_with_index do |row, row_index|
43
+ hash[sheet.name.to_sym]["#{row_index + 1}".to_sym] = {}
44
+ row.each_with_index do |val, index|
45
+ if val.class == Spreadsheet::Formula
46
+ if val.value.class == Spreadsheet::Excel::Error
47
+ hash[sheet.name.to_sym]["#{row_index + 1}".to_sym]["#{Converter.to_characters(index)}".to_sym] = FORMULA_ERROR
48
+ next
49
+ end
50
+ hash[sheet.name.to_sym]["#{row_index + 1}".to_sym]["#{Converter.to_characters(index)}".to_sym] = val.value
51
+ else
52
+ hash[sheet.name.to_sym]["#{row_index + 1}".to_sym]["#{Converter.to_characters(index)}".to_sym] = val
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
36
58
 
37
59
  def self.kill(object)
38
60
  object = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_xls_to_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - woodcrust
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spreadsheet
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - bin/fast_xls_to_hash
92
92
  - lib/fast_xls_to_hash.rb
93
+ - lib/fast_xls_to_hash/convert_number_to_xls_column/number_to_xls_column.rb
93
94
  - lib/fast_xls_to_hash/version.rb
94
95
  - lib/fast_xls_to_hash/xls/parse.rb
95
96
  - spec/fast_xls_to_hash_spec.rb