creek 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 144f13f0eba1b81962017976302f6b2db2b47b60
4
- data.tar.gz: fa8fe5d9aecd0eab818f06027425a0bd28a15808
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2M3NGQxMDJmMTc3NDk5MDUzMjFiNTU4NWI1ODZmMjBiNThkYzgyYg==
5
+ data.tar.gz: !binary |-
6
+ NWE3YmRhNGI5NTkwMDgzNDFiMDJkMmYzYzI1NjNiYjY2MDE0NmQ0Yw==
5
7
  SHA512:
6
- metadata.gz: 6ae590ddf3d095381c2cde2109b90bd1b44637120bcbc24257325fa3283cae6f5fcf35f75778f7b425556bc6c9aeff3c897c018c91f3726e66004d9a56d1b510
7
- data.tar.gz: 2f7abb6a3889bbf25fe78165244ed62e265a60b4ea4a3d598a6c0865c8188d4037d281b93c1069f694dcac3ec14c4bcd5765bc0cd1469247adeb714dc6c55e68
8
+ metadata.gz: !binary |-
9
+ ZjdmNjdmOTM1Zjc1OGIyNjI1YWZiNjlmNmJhZDliZDViMDJjODE5NDEzNzJi
10
+ NjI5MTkxMTYyNTRhMDhkODkxOGExY2E1MTVlMmZkODEwMTM4M2NlYjgyODI2
11
+ MDcxMjFmMzNmZDA2ZWU3MWM3OWJmNWRhMzAyYzgxM2E0NzdkODk=
12
+ data.tar.gz: !binary |-
13
+ ZmYxNDFiYzU0MDM1Y2FlMjgxZmI4OGI2OTRiYTQzMTI2OGRhMGYxNjlhNTU0
14
+ MzFjNTY5MjA5M2ZjY2MyODA3MDljYzYwZTNhNmZjZTAzMGQ4ZDFmMTNjNzU1
15
+ MTU5Y2I1M2Q3ZGU3YWE1Y2VjZDVhMDY3NTVlYzc1NmEyNmZlODU=
@@ -1,5 +1,6 @@
1
1
  require 'zip/filesystem'
2
2
  require 'nokogiri'
3
+ require 'date'
3
4
 
4
5
  module Creek
5
6
 
@@ -9,6 +10,9 @@ module Creek
9
10
  :sheets,
10
11
  :shared_strings
11
12
 
13
+ DATE_1900 = Date.new(1899, 12, 30).freeze
14
+ DATE_1904 = Date.new(1904, 1, 1).freeze
15
+
12
16
  def initialize path, options = {}
13
17
  check_file_extension = options.fetch(:check_file_extension, true)
14
18
  if check_file_extension
@@ -37,5 +41,26 @@ module Creek
37
41
  def close
38
42
  @files.close
39
43
  end
44
+
45
+ def base_date
46
+ @base_date ||=
47
+ begin
48
+ # Default to 1900 (minus one day due to excel quirk) but use 1904 if
49
+ # it's set in the Workbook's workbookPr
50
+ # http://msdn.microsoft.com/en-us/library/ff530155(v=office.12).aspx
51
+ result = DATE_1900 # default
52
+
53
+ doc = @files.file.open "xl/workbook.xml"
54
+ xml = Nokogiri::XML::Document.parse doc
55
+ xml.css('workbookPr[date1904]').each do |workbookPr|
56
+ if workbookPr['date1904'] =~ /true|1/i
57
+ result = DATE_1904
58
+ break
59
+ end
60
+ end
61
+
62
+ result
63
+ end
64
+ end
40
65
  end
41
66
  end
@@ -21,13 +21,6 @@ module Creek
21
21
  @rid = rid
22
22
  @state = state
23
23
  @sheetfile = sheetfile
24
-
25
- # An XLS file has only 256 columns, however, an XLSX or XLSM file can contain up to 16384 columns.
26
- # This function creates a hash with all valid XLSX column names and associated indices.
27
- @excel_col_names = Hash.new
28
- (0...16384).each do |i|
29
- @excel_col_names[col_name(i)] = i
30
- end
31
24
  end
32
25
 
33
26
  ##
@@ -45,13 +38,6 @@ module Creek
45
38
  end
46
39
 
47
40
  private
48
- ##
49
- # Returns valid Excel column name for a given column index.
50
- # For example, returns "A" for 0, "B" for 1 and "AQ" for 42.
51
- def col_name i
52
- quot = i/26
53
- (quot>0 ? col_name(quot-1) : "") + (i%26+65).chr
54
- end
55
41
 
56
42
  ##
57
43
  # Returns a hash per row that includes the cell ids and values.
@@ -64,7 +50,7 @@ module Creek
64
50
  opener = Nokogiri::XML::Reader::TYPE_ELEMENT
65
51
  closer = Nokogiri::XML::Reader::TYPE_END_ELEMENT
66
52
  Enumerator.new do |y|
67
- shared, row, cells, cell = false, nil, {}, nil
53
+ row, cells, cell = nil, {}, nil
68
54
  cell_type = nil
69
55
  cell_style_idx = nil
70
56
  @book.files.file.open(path) do |xml|
@@ -82,9 +68,8 @@ module Creek
82
68
  cell_type = node.attributes['t']
83
69
  cell_style_idx = node.attributes['s']
84
70
  cell = node.attributes['r']
85
-
86
71
  elsif (node.name.eql? 'v') and (node.node_type.eql? opener)
87
- if !cell.nil?
72
+ unless cell.nil?
88
73
  cells[cell] = convert(node.inner_xml, cell_type, cell_style_idx)
89
74
  end
90
75
  end
@@ -100,29 +85,28 @@ module Creek
100
85
  end
101
86
 
102
87
  def converter_options
103
- @converter_options ||= {shared_strings: @book.shared_strings.dictionary}
88
+ @converter_options ||= {
89
+ shared_strings: @book.shared_strings.dictionary,
90
+ base_date: @book.base_date
91
+ }
104
92
  end
105
93
 
106
94
  ##
107
95
  # The unzipped XML file does not contain any node for empty cells.
108
96
  # Empty cells are being padded in using this function
109
- def fill_in_empty_cells cells, row_number, last_col
97
+ def fill_in_empty_cells(cells, row_number, last_col)
110
98
  new_cells = Hash.new
99
+
111
100
  unless cells.empty?
112
- keys = cells.keys.sort
113
101
  last_col = last_col.gsub(row_number, '')
114
- last_col_index = @excel_col_names[last_col]
115
- [*(0..last_col_index)].each do |i|
116
- col = col_name i
117
- id = "#{col}#{row_number}"
118
- unless cells.has_key? id
119
- new_cells[id] = nil
120
- else
121
- new_cells[id] = cells[id]
122
- end
102
+
103
+ ("A"..last_col).to_a.each do |column|
104
+ id = "#{column}#{row_number}"
105
+ new_cells[id] = cells[id]
123
106
  end
124
107
  end
108
+
125
109
  new_cells
126
110
  end
127
111
  end
128
- end
112
+ end
@@ -1,5 +1,3 @@
1
- require 'date'
2
-
3
1
  module Creek
4
2
  class Styles
5
3
  module Constants
@@ -38,9 +36,6 @@ module Creek
38
36
  48 => :bignum, # ##0.0E+0
39
37
  49 => :unsupported # @
40
38
  }
41
-
42
- DATE_SYSTEM_1900 = Date.new(1899, 12, 30)
43
- DATE_SYSTEM_1904 = Date.new(1904, 1, 1)
44
39
  end
45
40
  end
46
41
  end
@@ -81,7 +81,7 @@ module Creek
81
81
  fraction_of_24 = value - days_since_date_system_start
82
82
 
83
83
  # http://stackoverflow.com/questions/10559767/how-to-convert-ms-excel-date-from-float-to-date-format-in-ruby
84
- date = options.fetch(:base_date, DATE_SYSTEM_1900) + days_since_date_system_start
84
+ date = options.fetch(:base_date, Date.new(1899, 12, 30)) + days_since_date_system_start
85
85
 
86
86
  if fraction_of_24 > 0 # there is a time associated
87
87
  seconds = (fraction_of_24 * 86400).round
@@ -98,21 +98,6 @@ module Creek
98
98
  value.to_f
99
99
  end
100
100
  end
101
-
102
- ## Returns the base_date from which to calculate dates.
103
- # Defaults to 1900 (minus two days due to excel quirk), but use 1904 if
104
- # it's set in the Workbook's workbookPr.
105
- # http://msdn.microsoft.com/en-us/library/ff530155(v=office.12).aspx
106
- def base_date
107
- @base_date ||= begin
108
- # return DATE_SYSTEM_1900 if xml.workbook == nil
109
- # xml.workbook.xpath("//workbook/workbookPr[@date1904]").each do |workbookPr|
110
- # return DATE_SYSTEM_1904 if workbookPr["date1904"] =~ /true|1/i
111
- # end
112
- DATE_SYSTEM_1900
113
- end
114
- end
115
-
116
101
  end
117
102
  end
118
103
  end
@@ -1,3 +1,3 @@
1
1
  module Creek
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creek
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pythonicrubyist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-18 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.13.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.13.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.6.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.6.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubyzip
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.0.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.0.0
97
97
  description: A Ruby gem that streams and parses large Excel(xlsx and xlsm) files fast
@@ -102,7 +102,7 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".gitignore"
105
+ - .gitignore
106
106
  - Gemfile
107
107
  - LICENSE.txt
108
108
  - README.rdoc
@@ -139,17 +139,17 @@ require_paths:
139
139
  - lib
140
140
  required_ruby_version: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - ">="
142
+ - - ! '>='
143
143
  - !ruby/object:Gem::Version
144
144
  version: 1.9.2
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - ">="
147
+ - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.4.8
152
+ rubygems_version: 2.4.3
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: A Ruby gem for parsing large Excel(xlsx and xlsm) files.