remote_table 0.2.29 → 0.2.30

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.29
1
+ 0.2.30
@@ -1,18 +1,31 @@
1
1
  class RemoteTable
2
2
  module RooSpreadsheet
3
3
  def each_row(&block)
4
- headers = Hash.new
5
4
  oo = roo_klass.new(path, nil, :ignore)
6
5
  oo.default_sheet = sheet.is_a?(Numeric) ? oo.sheets[sheet] : sheet
7
- for col in (1..oo.last_column)
8
- headers[col] = oo.cell(header_row, col)
9
- headers[col] = oo.cell(header_row - 1, col) if headers[col].blank? # look up
6
+ column_references = Hash.new
7
+ if headers == false
8
+ # zero-based numeric keys
9
+ for col in (1..oo.last_column)
10
+ column_references[col] = col - 1
11
+ end
12
+ elsif headers.is_a? Array
13
+ # names
14
+ for col in (1..oo.last_column)
15
+ column_references[col] = headers[col - 1]
16
+ end
17
+ else
18
+ # read headers from the file itself
19
+ for col in (1..oo.last_column)
20
+ column_references[col] = oo.cell(header_row, col)
21
+ column_references[col] = oo.cell(header_row - 1, col) if column_references[col].blank? # look up
22
+ end
10
23
  end
11
24
  first_data_row.upto(oo.last_row) do |raw_row|
12
25
  ordered_hash = ActiveSupport::OrderedHash.new
13
26
  for col in (1..oo.last_column)
14
- next if headers[col].blank?
15
- ordered_hash[headers[col]] = oo.cell(raw_row, col).to_s.gsub(/<[^>]+>/, '').strip
27
+ next if column_references[col].blank?
28
+ ordered_hash[column_references[col]] = oo.cell(raw_row, col).to_s.gsub(/<[^>]+>/, '').strip
16
29
  end
17
30
  yield ordered_hash if keep_blank_rows or ordered_hash.any? { |k, v| v.present? }
18
31
  end
data/remote_table.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{remote_table}
8
- s.version = "0.2.29"
8
+ s.version = "0.2.30"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
@@ -130,6 +130,16 @@ class RemoteTableTest < Test::Unit::TestCase
130
130
  end
131
131
 
132
132
  if ENV['ALL'] == 'true' or ENV['FAST'] == 'true'
133
+ should "open an XLSX like an array (numbered columns)" do
134
+ t = RemoteTable.new(:url => 'www.customerreferenceprogram.org/uploads/CRP_RFP_template.xlsx', :headers => false)
135
+ assert_equal "Secure encryption of all data", t.rows[5][0]
136
+ end
137
+
138
+ should "open an XLSX with custom headers" do
139
+ t = RemoteTable.new(:url => 'www.customerreferenceprogram.org/uploads/CRP_RFP_template.xlsx', :headers => %w{foo bar baz})
140
+ assert_equal "Secure encryption of all data", t.rows[5]['foo']
141
+ end
142
+
133
143
  should "open an XLSX" do
134
144
  t = RemoteTable.new(:url => 'www.customerreferenceprogram.org/uploads/CRP_RFP_template.xlsx')
135
145
  assert_equal "Secure encryption of all data", t.rows[5]["Requirements"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_table
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 43
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 29
10
- version: 0.2.29
9
+ - 30
10
+ version: 0.2.30
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere