xsv 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: e21f0a8d16ae47d4f467f2a329a3fb50122d5386aa7459f7a04cf83594814752
4
- data.tar.gz: ee74ecd24d93c200df5626748e17b300c6147a9c7d7442ed5913ee80e7bcb500
3
+ metadata.gz: 9fde081e219b3d4ae14aaa9d29de699e67df263ff0d8bfa1ffc10362099dc8eb
4
+ data.tar.gz: f2cd6e1ae40a06bcac62368a26f9cf09157d5394bbb7f9ab34473a90be729d37
5
5
  SHA512:
6
- metadata.gz: 9b95af14330be23be0003753112486e71980bc06073baa22054a725775fd17a246d1cb448816666bde6fffc9793c7cec242b143c28cac2b5d4dbeacfd78c89da
7
- data.tar.gz: b659683e0a6bc6c7bb661642bdc1dd94acf6af2fdfc3833e2cfd54f465981821117d133c551feb7c69673d88a1fe0be5881c79c02ab1443b4f714720737eb3db
6
+ metadata.gz: 24a1070748166f3d18fffced8b310825efa72c121b4226ce588686c18eb07f80a8c328848b7f1c0915b4c002ea656916db263441dd2a442a60dd828e4ba8ccde
7
+ data.tar.gz: 01530b8f31bc60aafbeb36a563faff5958bf98577ae3a85e527e217c0c988a5b5d4ef7e614811cdd590402312835b7f60c50c0a94c4a77bc0543729e41c6e826
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xsv (0.3.0)
4
+ xsv (0.3.2)
5
5
  ox (~> 2.13)
6
6
  rubyzip (~> 2.2)
7
7
 
data/lib/xsv/helpers.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
3
  module Helpers
3
4
  BUILT_IN_NUMBER_FORMATS = {
@@ -36,23 +37,19 @@ module Xsv
36
37
 
37
38
  MINUTE = 60.freeze
38
39
  HOUR = 3600.freeze
40
+ A_CODEPOINT = 'A'.ord.freeze
41
+ EPOCH = Date.new(1899, 12, 30).freeze
39
42
 
40
43
  # Return the index number for the given Excel column name
41
44
  def column_index(col)
42
45
  col = col[/^[A-Z]+/]
43
46
 
44
- val = 0
45
- while col.length > 0
46
- val *= 26
47
- val += (col[0].ord - "A".ord + 1)
48
- col = col[1..-1]
49
- end
50
- return val - 1
47
+ col.each_codepoint.reduce(0) { |sum, n| sum * 26 + (n - A_CODEPOINT + 1) } - 1
51
48
  end
52
49
 
53
50
  # Return a Date for the given Excel date value
54
51
  def parse_date(number)
55
- Date.new(1899, 12, 30) + number
52
+ EPOCH + number
56
53
  end
57
54
 
58
55
  # Return a time as a string for the given Excel time value
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
3
  class SharedStringsParser < Ox::Sax
3
4
  def self.parse(io)
data/lib/xsv/sheet.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
3
  class Sheet
3
4
  include Enumerable
@@ -69,7 +70,7 @@ module Xsv
69
70
  if @mode == :array
70
71
  first
71
72
  elsif @mode == :hash
72
- @mode == :array
73
+ @mode = :array
73
74
  headers.tap { @mode = :hash }
74
75
  end
75
76
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
3
  # SheetBoundsHandler scans a sheet looking for the outer bounds of the content within
3
4
  class SheetBoundsHandler < Ox::Sax
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
3
  class SheetRowsHandler < Ox::Sax
3
4
  include Xsv::Helpers
@@ -58,7 +59,7 @@ module Xsv
58
59
  when :c
59
60
  @state = name
60
61
  @current_cell = {}
61
- @current_value = ""
62
+ @current_value = String.new
62
63
  when :v
63
64
  @state = name
64
65
  when :row
@@ -72,7 +73,7 @@ module Xsv
72
73
 
73
74
  def text(value)
74
75
  if @state == :v
75
- @current_value += value
76
+ @current_value << value
76
77
  end
77
78
  end
78
79
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
3
  # StylesHandler interprets the relevant parts of styles.xml
3
4
  class StylesHandler < Ox::Sax
data/lib/xsv/version.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Xsv
2
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
3
4
  end
data/lib/xsv/workbook.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'zip'
2
3
 
3
4
  module Xsv
@@ -8,11 +9,11 @@ module Xsv
8
9
  # Open the workbook of the given filename, string or buffer
9
10
  def self.open(data, **kws)
10
11
  if data.is_a?(IO)
11
- @workbook = self.new(Zip::File.open_buffer(data), kws)
12
+ @workbook = self.new(Zip::File.open_buffer(data), **kws)
12
13
  elsif data.start_with?("PK\x03\x04")
13
- @workbook = self.new(Zip::File.open_buffer(data), kws)
14
+ @workbook = self.new(Zip::File.open_buffer(data), **kws)
14
15
  else
15
- @workbook = self.new(Zip::File.open(data), kws)
16
+ @workbook = self.new(Zip::File.open(data), **kws)
16
17
  end
17
18
  end
18
19
 
data/lib/xsv.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "date"
2
3
  require "ox"
3
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martijn Storck
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.0.3
132
+ rubygems_version: 3.1.2
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Minimal xlsx parser that provides nothing a CSV parser wouldn't