tabulator 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -1
- data/lib/tabulator/reader.rb +41 -11
- data/lib/tabulator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69cb8828c5819d9e55c461da4cb684605ab2d49a
|
4
|
+
data.tar.gz: 47d7c2c528498616060927bcacb0aa605aca8f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3ef74757271054d3828f4ce41461863e8c61c964046778f63d5a16c16c5e6dada531f9e5be8d22908b2e4734d19de9d66847798ed503048decb089576ffff1b
|
7
|
+
data.tar.gz: 8528bfcd72c5012bb309b49d9b83a081bfcb610c949a2875092a1cf487648ca85b011e10deac7baf21d20bdf4296d4f85dbcf5653766b7d8b054be5030e36977
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Tabulator
|
2
2
|
|
3
|
+
[](https://travis-ci.org/chapuzzo/tabulator)
|
4
|
+
|
3
5
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tabulator`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
6
|
|
5
7
|
TODO: Delete this and the text above, and describe your gem
|
@@ -32,5 +34,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
34
|
|
33
35
|
## Contributing
|
34
36
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chapuzzo/tabulator.
|
36
38
|
|
data/lib/tabulator/reader.rb
CHANGED
@@ -11,26 +11,56 @@ module Tabulator
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def [] worksheet
|
14
|
-
Worksheet.
|
14
|
+
Worksheet.build @file.worksheets[worksheet].rows
|
15
15
|
end
|
16
16
|
|
17
17
|
class Worksheet
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
def self.build rows, **options
|
20
|
+
header = options[:header] || 0
|
21
|
+
skip = options[:skip] || header + 1
|
22
|
+
|
23
|
+
rejected_rows = *options[:reject]
|
24
|
+
|
25
|
+
rejected_rows.each { |index_definition|
|
26
|
+
next rows.delete_if &index_definition if index_definition.is_a? Proc
|
27
|
+
rows.slice! index_definition
|
28
|
+
}
|
29
|
+
|
30
|
+
header_row = rows[header].map { |raw_header_col|
|
31
|
+
I18n.transliterate(raw_header_col.strip.gsub(/\s/, '_')).downcase.to_sym
|
32
|
+
}
|
33
|
+
|
34
|
+
new rows.drop(skip).map { |row|
|
35
|
+
header_row.zip(row).to_h
|
36
|
+
}
|
20
37
|
end
|
21
38
|
|
22
|
-
def rows
|
23
|
-
@
|
39
|
+
def initialize rows
|
40
|
+
@rows = rows
|
24
41
|
end
|
25
42
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
43
|
+
def only *cols
|
44
|
+
self.class.new to_a.map { |row|
|
45
|
+
row.select { |title, _|
|
46
|
+
cols.include? title
|
47
|
+
}
|
29
48
|
}
|
49
|
+
end
|
30
50
|
|
31
|
-
|
32
|
-
|
33
|
-
|
51
|
+
def apply target
|
52
|
+
self.class.new to_a.map { |row|
|
53
|
+
row[target] = yield row[target]
|
54
|
+
row
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_a
|
59
|
+
Marshal.load(Marshal.dump(@rows))
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_json
|
63
|
+
to_a.to_json(json_dump_options)
|
34
64
|
end
|
35
65
|
|
36
66
|
def save path
|
data/lib/tabulator/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chapuzzo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google_drive
|