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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11abdefda51f4bdba38ef543748a07a02550079b
4
- data.tar.gz: 1d4a6bcb7892170e89d184920fb3c404737cc3b7
3
+ metadata.gz: 69cb8828c5819d9e55c461da4cb684605ab2d49a
4
+ data.tar.gz: 47d7c2c528498616060927bcacb0aa605aca8f6b
5
5
  SHA512:
6
- metadata.gz: 213f8a890fa55bc71f572aeae530079af63c4c6fa6a4f27ce90df449cbe96c5266fe78185128028c99128c20690126d0e8ee68b255735eab5d26321bedb72ef7
7
- data.tar.gz: b16020c6c9fb3582c8837a02e430ae740417b0110a54ceae0b026be823bc349a8ba5520873bae19a46e7a30e9187dafaaff55492b1d7fedfc93ba5eff7e5a184
6
+ metadata.gz: b3ef74757271054d3828f4ce41461863e8c61c964046778f63d5a16c16c5e6dada531f9e5be8d22908b2e4734d19de9d66847798ed503048decb089576ffff1b
7
+ data.tar.gz: 8528bfcd72c5012bb309b49d9b83a081bfcb610c949a2875092a1cf487648ca85b011e10deac7baf21d20bdf4296d4f85dbcf5653766b7d8b054be5030e36977
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  config.json
11
+ cli.rb
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Tabulator
2
2
 
3
+ [![Build Status](https://travis-ci.org/chapuzzo/tabulator.svg?branch=master)](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/[USERNAME]/tabulator.
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chapuzzo/tabulator.
36
38
 
@@ -11,26 +11,56 @@ module Tabulator
11
11
  end
12
12
 
13
13
  def [] worksheet
14
- Worksheet.new @file.worksheets[worksheet]
14
+ Worksheet.build @file.worksheets[worksheet].rows
15
15
  end
16
16
 
17
17
  class Worksheet
18
- def initialize worksheet
19
- @worksheet = worksheet
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
- @worksheet.rows
39
+ def initialize rows
40
+ @rows = rows
24
41
  end
25
42
 
26
- def to_json
27
- header = rows.first.map { |raw_header_col|
28
- I18n.transliterate(raw_header_col.strip.gsub(/\s/, '_')).downcase.to_sym
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
- rows.drop(1).map { |row|
32
- header.zip(row).to_h
33
- }.to_json(json_dump_options)
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
@@ -1,3 +1,3 @@
1
1
  module Tabulator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-01-25 00:00:00.000000000 Z
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive