spreadsheet_goodies 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/builds/spreadsheet_goodies-0.0.1.gem +0 -0
- data/builds/spreadsheet_goodies-0.0.2.gem +0 -0
- data/builds/spreadsheet_goodies-0.0.3.gem +0 -0
- data/lib/spreadsheet_goodies.rb +3 -3
- data/lib/spreadsheet_goodies/{excel_worksheet_proxy.rb → excel_worksheet.rb} +5 -5
- data/lib/spreadsheet_goodies/{excel_worksheet_proxy_row.rb → excel_worksheet_row.rb} +2 -2
- data/lib/spreadsheet_goodies/{google_worksheet_proxy.rb → google_drive_worksheet.rb} +10 -3
- data/lib/spreadsheet_goodies/{google_worksheet_proxy_row.rb → google_drive_worksheet_row.rb} +2 -2
- data/lib/spreadsheet_goodies/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ac665483c2a857085d25a1237cbab883b2b12c3
|
4
|
+
data.tar.gz: 01d5aeed49efd551611bfc80981258a9d4346dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f963fcdda1e06d423fdb49584e9d19e7b8507eb2a20bbebd0ca4716b01b6aef9134594819aede023b1dfd044cbb93e48209ef1e173f8a52e5b5bd0e281d0d0f7
|
7
|
+
data.tar.gz: 2c03a6bb43be7e8794ea8d03e8f7c23b4a226b16b6d777d1aff7309526a2467d077d7a2bee5e5463fdd8dea78750940d1948125dc2e91311d0113fe3d244ad37
|
data/README.md
CHANGED
@@ -30,12 +30,12 @@ Or install it yourself as:
|
|
30
30
|
Read a Google Spreadsheet:
|
31
31
|
```
|
32
32
|
spreadsheet_key = '1UC43X6aZwlWPCnn...', '~> 0'#, '~> 1.13.2'
|
33
|
-
sheet = SpreadsheetGoodies::
|
33
|
+
sheet = SpreadsheetGoodies::GoogleDriveWorksheet.new(spreadsheet_key, 'Relação Lojas').read_from_google_drive
|
34
34
|
```
|
35
35
|
|
36
36
|
Read an Excel workbook:
|
37
37
|
```
|
38
|
-
sheet = SpreadsheetGoodies::
|
38
|
+
sheet = SpreadsheetGoodies::ExcelWorksheet.new('~/workbook.xlsx')
|
39
39
|
```
|
40
40
|
|
41
41
|
Iterate over every data row (i.e., all but the header row) and print the value
|
Binary file
|
Binary file
|
Binary file
|
data/lib/spreadsheet_goodies.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spreadsheet_goodies/version'
|
2
|
-
require 'spreadsheet_goodies/
|
2
|
+
require 'spreadsheet_goodies/google_drive_worksheet'
|
3
3
|
require 'spreadsheet_goodies/google_drive_connector'
|
4
|
-
require 'spreadsheet_goodies/
|
4
|
+
require 'spreadsheet_goodies/excel_worksheet'
|
5
5
|
require 'roo'
|
6
6
|
|
7
7
|
module SpreadsheetGoodies
|
@@ -24,7 +24,7 @@ module SpreadsheetGoodies
|
|
24
24
|
|
25
25
|
class Configuration
|
26
26
|
attr_accessor :service_account_key_json, :login_method,
|
27
|
-
:google_client_id, :client_secret, :refresh_token
|
27
|
+
:google_client_id, :client_secret, :refresh_token, :strip_values_on_read
|
28
28
|
|
29
29
|
def initialize
|
30
30
|
@login_method = :oauth2
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'excel_worksheet_row'
|
2
2
|
|
3
3
|
# A cached copy of an Excel worksheet (a single workbook "tab"), stored as an
|
4
4
|
# array of arrays. Individual cells can be accessed by column title, e.g.:
|
5
5
|
# worksheet[0]['A column title']
|
6
|
-
class SpreadsheetGoodies::
|
6
|
+
class SpreadsheetGoodies::ExcelWorksheet
|
7
7
|
attr_reader :rows, :workbook, :worksheet
|
8
8
|
|
9
9
|
# @param workbook_file_pathname [String] Full path and filename to Excel workbook document
|
@@ -30,9 +30,9 @@ class SpreadsheetGoodies::ExcelWorksheetProxy
|
|
30
30
|
# was missed some times.)
|
31
31
|
rows = (1..@worksheet.last_row).map {|row_number| @worksheet.row(row_number) }
|
32
32
|
|
33
|
-
# Create the rows cache, made of instances of
|
33
|
+
# Create the rows cache, made of instances of ExcelWorksheetRow
|
34
34
|
@rows = rows.collect.with_index do |row, index|
|
35
|
-
|
35
|
+
ExcelWorksheetRow.new(@header_row, index+1, *row)
|
36
36
|
end
|
37
37
|
|
38
38
|
self
|
@@ -58,7 +58,7 @@ class SpreadsheetGoodies::ExcelWorksheetProxy
|
|
58
58
|
|
59
59
|
def add_row(row_data)
|
60
60
|
last_row_number = @rows.count
|
61
|
-
@rows <<
|
61
|
+
@rows << ExcelWorksheetRow.new(@header_row, last_row_number+1, *row_data)
|
62
62
|
end
|
63
63
|
|
64
64
|
def spreadsheet
|
@@ -1,8 +1,8 @@
|
|
1
|
-
class SpreadsheetGoodies::
|
1
|
+
class SpreadsheetGoodies::ExcelWorksheet
|
2
2
|
|
3
3
|
# Overload Array#[] to allow reading a cell's contents using its column title
|
4
4
|
# as index, e.g.: row['Column Title']
|
5
|
-
class ::
|
5
|
+
class ::ExcelWorksheetRow < Array
|
6
6
|
attr_reader :header_row, :row_number
|
7
7
|
|
8
8
|
# @param header_row [Array] The header cells of the sheet from were the row was taken
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'google_drive_worksheet_row'
|
2
2
|
require 'csv'
|
3
3
|
|
4
4
|
# A cached copy of a Google Spreadsheets worksheet (i.e., a single workbook "tab"),
|
5
5
|
# stored as an array of arrays. Individual cells can be accessed by column title.
|
6
6
|
# Example:
|
7
7
|
# worksheet[0]['A column title']
|
8
|
-
class SpreadsheetGoodies::
|
8
|
+
class SpreadsheetGoodies::GoogleDriveWorksheet
|
9
9
|
attr_reader :rows, :header_row
|
10
10
|
|
11
11
|
# @param worksheet_title_or_index [String] Sheet name; if unspecified, the
|
@@ -25,9 +25,16 @@ class SpreadsheetGoodies::GoogleWorksheetProxy
|
|
25
25
|
worksheet_contents = read_worksheet.export_as_string.force_encoding('utf-8')
|
26
26
|
|
27
27
|
rows = CSV::parse(worksheet_contents)
|
28
|
+
|
29
|
+
if SpreadsheetGoodies.configuration.strip_values_on_read
|
30
|
+
rows = rows.map do |row|
|
31
|
+
row.map {|element| element.try(:strip) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
28
35
|
@header_row = rows[@num_header_rows-1]
|
29
36
|
@rows = rows.collect.with_index do |row, index|
|
30
|
-
|
37
|
+
GoogleDriveWorksheetRow.new(@header_row, index+1, *row)
|
31
38
|
end
|
32
39
|
|
33
40
|
self
|
data/lib/spreadsheet_goodies/{google_worksheet_proxy_row.rb → google_drive_worksheet_row.rb}
RENAMED
@@ -1,8 +1,8 @@
|
|
1
|
-
class SpreadsheetGoodies::
|
1
|
+
class SpreadsheetGoodies::GoogleDriveWorksheet
|
2
2
|
|
3
3
|
# Sobrecarrega método [] da Array para permitir acessar células passando
|
4
4
|
# o título da coluna como índice. Ex: row['Data formal do pedido']
|
5
|
-
class ::
|
5
|
+
class ::GoogleDriveWorksheetRow < Array
|
6
6
|
attr_reader :header_row, :row_number
|
7
7
|
|
8
8
|
def initialize(header_row, sheet_row_number, *args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreadsheet_goodies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Jasinski
|
@@ -130,13 +130,15 @@ files:
|
|
130
130
|
- bin/console
|
131
131
|
- bin/setup
|
132
132
|
- builds/spreadsheet_goodies-0.0.1.gem
|
133
|
+
- builds/spreadsheet_goodies-0.0.2.gem
|
134
|
+
- builds/spreadsheet_goodies-0.0.3.gem
|
133
135
|
- lib/spreadsheet_goodies.rb
|
134
136
|
- lib/spreadsheet_goodies/excel_workbook_builder.rb
|
135
|
-
- lib/spreadsheet_goodies/
|
136
|
-
- lib/spreadsheet_goodies/
|
137
|
+
- lib/spreadsheet_goodies/excel_worksheet.rb
|
138
|
+
- lib/spreadsheet_goodies/excel_worksheet_row.rb
|
137
139
|
- lib/spreadsheet_goodies/google_drive_connector.rb
|
138
|
-
- lib/spreadsheet_goodies/
|
139
|
-
- lib/spreadsheet_goodies/
|
140
|
+
- lib/spreadsheet_goodies/google_drive_worksheet.rb
|
141
|
+
- lib/spreadsheet_goodies/google_drive_worksheet_row.rb
|
140
142
|
- lib/spreadsheet_goodies/version.rb
|
141
143
|
- spreadsheet_goodies.gemspec
|
142
144
|
homepage: https://github.com/ricardo-jasinski/spreadsheet_goodies
|