tableware 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semver +6 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +3 -1
- data/README.md +28 -59
- data/Rakefile +0 -1
- data/lib/tableware/parser.rb +1 -1
- data/lib/tableware/version.rb +1 -1
- data/tableware.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 726ade1c9944387517bd3d7bbac38f5ba2584a30
|
4
|
+
data.tar.gz: e2fddc4507e8fa04c3144290e104b9d171c30e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8611a0c543306410ac5e9252e8614c386931d83d1511f5edf41ef4bd198a10fdf63f2cc98f807edaea2d9a221903151a8fa6371a9ab585e2a4f1d98e78eb93
|
7
|
+
data.tar.gz: 3e4ec20fcd80ef69f7ff38d05d6ec0bbcc02ad14775a468ba3ba5eadb21c52843865bb5ba08b430606ce5d4db61a9218031ad5f873e3ec729e76770a07011b2b
|
data/.semver
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tableware (0.1.
|
4
|
+
tableware (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -85,6 +85,7 @@ GEM
|
|
85
85
|
parser (>= 2.2.0, < 3.0)
|
86
86
|
reek (= 3.8.1)
|
87
87
|
virtus (~> 1.0)
|
88
|
+
semver2 (3.4.2)
|
88
89
|
sexp_processor (4.6.1)
|
89
90
|
simplecov (0.11.2)
|
90
91
|
docile (~> 1.1.0)
|
@@ -121,6 +122,7 @@ DEPENDENCIES
|
|
121
122
|
rspec (~> 3.0)
|
122
123
|
rubocop
|
123
124
|
rubycritic
|
125
|
+
semver2
|
124
126
|
simplecov
|
125
127
|
tableware!
|
126
128
|
|
data/README.md
CHANGED
@@ -3,43 +3,42 @@
|
|
3
3
|
Tableware is a tiny gem for making it easier to define data in an text table.
|
4
4
|
Table rows are parsed into either arrays or hashes.
|
5
5
|
|
6
|
-
For example
|
6
|
+
For example:
|
7
7
|
|
8
|
-
```
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
// Some test or permissions check or something
|
15
|
-
end
|
16
|
-
```
|
17
|
-
is fine but it can be a pain to format at work with, especially for larger data sets.
|
8
|
+
```ruby
|
9
|
+
stats = ' Hero | Value | Hours Played
|
10
|
+
------------------------------------------
|
11
|
+
Phara | 10 | 22
|
12
|
+
Mercy | 9 | 11
|
13
|
+
Winston | 3 | 2 '
|
18
14
|
|
19
|
-
Tableware
|
15
|
+
Tableware.arrays(stats)
|
16
|
+
# => [
|
17
|
+
['Phara', '10', '22'],
|
18
|
+
['Mercy', '9', '11'],
|
19
|
+
['Winston', '3', '2']
|
20
|
+
]
|
20
21
|
|
22
|
+
Tableware.hashes(stats)
|
23
|
+
#=> [
|
24
|
+
{ hero: 'Phara', value: '10', hours_played: 22 },
|
25
|
+
{ hero: 'Mercy', value: '9', hours_played: 11 },
|
26
|
+
{ hero: 'Winston', value: '3', hours_played: 2 }
|
27
|
+
]
|
21
28
|
```
|
22
|
-
table = %q[
|
23
|
-
| Type | Valid | Infinite | Year Introduced |
|
24
|
-
----------------------------------------------------------------------------------
|
25
|
-
| Type A | true | false | 2016 |
|
26
|
-
| Type B | Only on alternating Wednesdays | false | 2017 |
|
27
|
-
| Type C | never | true | 2016 |
|
28
|
-
]
|
29
|
-
Tableware.arrays.each do |args|
|
30
|
-
// Some test or permissions check or something
|
31
|
-
end
|
32
|
-
```
|
33
29
|
|
34
|
-
|
35
|
-
|
30
|
+
Writing test data or a matrix of permissions in a big hash or nested array is fine, but it can be a pain to format at work with, especially for larger data setsa or with item of very different lengths.
|
31
|
+
|
32
|
+
Tableware lets you use a more human friendly format so that you can more easily scan and understand the data.
|
36
33
|
|
37
|
-
|
38
|
-
Whatever your reasoning, this is just one more option for formatting your data.
|
34
|
+
The downside is that everything is treated as a string, so you may need to do some `.to_i`ing to convert things back into the type you're expecting. However, this is a one-time cost and [optimising for reading code is a good idea](http://va.lent.in/optimize-for-readability-first/).
|
39
35
|
|
40
|
-
This
|
36
|
+
This isn't always going to be better than defining your data in another format, but it is another option. Or perhaps you just like Cucumber scenario outlines and want something similar in rspec!
|
37
|
+
|
38
|
+
This gem has been created as a quick experiment to see if or how ofen this feature could be useful.
|
41
39
|
If you find it useful, please like it or better yet, extend it!
|
42
40
|
|
41
|
+
|
43
42
|
## Installation
|
44
43
|
|
45
44
|
Add this line to your application's Gemfile:
|
@@ -70,38 +69,8 @@ Tableware provides two main methods for getting your data back out of the table:
|
|
70
69
|
1. `Tableware.arrays` returns an array of arrays
|
71
70
|
2. `Tableware.hashes` returns an array of hashes, where the keys come from the headings row
|
72
71
|
|
72
|
+
Both of these can be seen in use in the example at the top of this README.
|
73
73
|
|
74
|
-
For example:
|
75
|
-
|
76
|
-
```
|
77
|
-
input = '
|
78
|
-
Hero | Value | Hours Played
|
79
|
-
------------------------------------------
|
80
|
-
Phara | 10 | 22
|
81
|
-
Mercy | 9 | 11
|
82
|
-
Winston | 3 | 2
|
83
|
-
'
|
84
|
-
|
85
|
-
Tableware.arrays(input)
|
86
|
-
# => [
|
87
|
-
['Phara', '10', '22'],
|
88
|
-
['Mercy', '9', '11'],
|
89
|
-
['Winston', '3', '2']
|
90
|
-
]
|
91
|
-
|
92
|
-
Tableware.hashes(input)
|
93
|
-
#=> [
|
94
|
-
{ hero: 'Phara', value: '10', hours_played: 22 },
|
95
|
-
{ hero: 'Mercy', value: '9', hours_played: 11 },
|
96
|
-
{ hero: 'Winston', value: '3', hours_played: 2 }
|
97
|
-
]
|
98
|
-
```
|
99
|
-
|
100
|
-
## Development
|
101
|
-
|
102
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
103
|
-
|
104
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
105
74
|
|
106
75
|
## Contributing
|
107
76
|
|
data/Rakefile
CHANGED
data/lib/tableware/parser.rb
CHANGED
@@ -25,7 +25,7 @@ class Tableware
|
|
25
25
|
private def prepare_lines(input)
|
26
26
|
lines = input.strip.lines
|
27
27
|
|
28
|
-
@data_start = lines[1] =~ /^\s*[
|
28
|
+
@data_start = lines[1] =~ /^\s*[-=\|]+\s*$/ ? 2 : 0
|
29
29
|
if @data_start.nonzero?
|
30
30
|
@headers = parse_line(lines[0])
|
31
31
|
.map!(&:downcase)
|
data/lib/tableware/version.rb
CHANGED
data/tableware.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tableware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Whittingham
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: semver2
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: A nice way of parsing text tables into Ararys or Hashes, for clearer
|
126
140
|
code. Great for tests and permissions matrixes!
|
127
141
|
email:
|
@@ -135,6 +149,9 @@ files:
|
|
135
149
|
- ".rubocop-https---raw-githubusercontent-com-dvmtn-house-style-master-rubocop-yml"
|
136
150
|
- ".rubocop.yml"
|
137
151
|
- ".ruby-version"
|
152
|
+
- ".semver"
|
153
|
+
- ".travis.yml"
|
154
|
+
- CHANGELOG.md
|
138
155
|
- CODE_OF_CONDUCT.md
|
139
156
|
- Gemfile
|
140
157
|
- Gemfile.lock
|