duplo 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/CHANGELOG.md +4 -0
- data/README.md +34 -21
- data/lib/duplo/version.rb +1 -1
- data/lib/duplo.rb +5 -1
- data/spec/duplo_spec.rb +17 -4
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ced13192f8a77859809d3f5152405b8b8277d422
|
4
|
+
data.tar.gz: 82096e9fd70ffb4a938ace1f83cf69bbd5a1cd38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81567d7e7c0185dde4fcb4982a56fd09c2fd65093ef0ce0487ec908b8fe2dec9f78210ce81a125e19b31e1139de89b934ff63b34fb147c19c1893d1edadda908
|
7
|
+
data.tar.gz: 32845ca94f81a928a665353c463320e7ac991c4ebe90e00f84f7e30fbb0f882be8f3245c7cf4e293bf9a6689a82f73dfe8035bafc552b61475ba25be78ed1a21
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
Duplo
|
2
2
|
=====
|
3
3
|
|
4
|
-
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/duplo.svg)](https://rubygems.org/gems/duplo)
|
5
|
+
[![Build Status](https://travis-ci.org/topalovic/duplo.svg?branch=master)](https://travis-ci.org/topalovic/duplo)
|
6
|
+
|
7
|
+
Generate nested collections with minimum effort.
|
5
8
|
|
6
9
|
```
|
7
|
-
.-===============-.
|
8
|
-
| ( ) ( ) ( ) ( ) |
|
9
|
-
| ( ) ( ) ( ) ( ) |
|
10
|
-
'-----------------' ndt.
|
10
|
+
.-===============-.
|
11
|
+
| ( ) ( ) ( ) ( ) |
|
12
|
+
| ( ) ( ) ( ) ( ) |
|
13
|
+
'-----------------' ndt.
|
11
14
|
```
|
12
15
|
|
13
16
|
|
14
17
|
## Usage
|
15
18
|
|
16
|
-
|
17
|
-
or writing nested loops to populate them.
|
18
|
-
to test something real quick in
|
19
|
-
a royal PITA.
|
19
|
+
Let's say you like matrices (bear with me), but not rolling them out
|
20
|
+
by hand or writing nested loops to populate them. Or you might need a
|
21
|
+
few nested hashes to test something real quick in the console, but
|
22
|
+
generating them can be a royal PITA.
|
20
23
|
|
21
24
|
So how about this:
|
22
25
|
|
@@ -41,20 +44,28 @@ a3a4 { rand }
|
|
41
44
|
# [0.37651300630626683, 0.5035024403835663, 0.8237420938739567, 0.7611012983149591]]
|
42
45
|
```
|
43
46
|
|
44
|
-
Accessing the current entry path is easy peasy
|
47
|
+
Accessing the current entry path is easy peasy. Have an identity
|
48
|
+
matrix:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
I4 = a4a4 { |i, j| i == j ? 1 : 0 }
|
52
|
+
# => [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
|
53
|
+
```
|
54
|
+
|
55
|
+
Have I mentioned that you can go up to an arbitrary number of
|
56
|
+
dimensions?
|
45
57
|
|
46
58
|
```ruby
|
47
59
|
a3a3a2 { |i,j,k| [i,j,k].join(":") }
|
48
60
|
# => [[["0:0:0", "0:0:1"], ["0:1:0", "0:1:1"], ["0:2:0", "0:2:1"]],
|
49
61
|
# [["1:0:0", "1:0:1"], ["1:1:0", "1:1:1"], ["1:2:0", "1:2:1"]],
|
50
62
|
# [["2:0:0", "2:0:1"], ["2:1:0", "2:1:1"], ["2:2:0", "2:2:1"]]]
|
51
|
-
|
63
|
+
```
|
52
64
|
|
53
|
-
|
54
|
-
|
55
|
-
to the recursive approach under the hood.
|
65
|
+
Heads up, it might get a bit sluggish with higher dims due to the
|
66
|
+
recursive approach under the hood.
|
56
67
|
|
57
|
-
|
68
|
+
Now how 'bout them Hashes:
|
58
69
|
|
59
70
|
```ruby
|
60
71
|
h3h2h2 { |path| "I'm a #{path.join}" }
|
@@ -76,7 +87,7 @@ ah2s3 { abc.sample(2).join }
|
|
76
87
|
```
|
77
88
|
|
78
89
|
You get the picture. If you're *really* bored, you can spell those out
|
79
|
-
|
90
|
+
loud:
|
80
91
|
|
81
92
|
```ruby
|
82
93
|
Duplo.spell "ah2s0"
|
@@ -85,7 +96,7 @@ Duplo.spell "ah2s0"
|
|
85
96
|
|
86
97
|
Note that I've omitted a dim for the root array in that last
|
87
98
|
example. It defaults to 5, so `as2h` means the same thing as
|
88
|
-
`a5s2h5`. You can easily change
|
99
|
+
`a5s2h5`. You can easily change it like this:
|
89
100
|
|
90
101
|
```ruby
|
91
102
|
Duplo.default_size = 3
|
@@ -97,8 +108,10 @@ alphabet as an array (as seen in the last example).
|
|
97
108
|
|
98
109
|
## Installation
|
99
110
|
|
100
|
-
You know the drill.
|
101
|
-
|
111
|
+
You know the drill.
|
112
|
+
|
113
|
+
Add this line to your application's Gemfile, presumably in the
|
114
|
+
"development" or "test" group:
|
102
115
|
|
103
116
|
```ruby
|
104
117
|
gem "duplo"
|
@@ -110,8 +123,8 @@ or install it yourself as:
|
|
110
123
|
$ gem install duplo
|
111
124
|
```
|
112
125
|
|
113
|
-
It's not
|
114
|
-
|
126
|
+
It's not really necessary to include the module, you can use it
|
127
|
+
directly:
|
115
128
|
|
116
129
|
```ruby
|
117
130
|
Duplo.a2a2
|
data/lib/duplo/version.rb
CHANGED
data/lib/duplo.rb
CHANGED
@@ -73,9 +73,13 @@ module Duplo
|
|
73
73
|
n ? range.take(n) : range.to_a
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def respond_to_missing?(method_name, *)
|
77
77
|
toy = method_name.to_s
|
78
|
+
Duplo.can_build?(toy) || super
|
79
|
+
end
|
78
80
|
|
81
|
+
def method_missing(method_name, *arguments, &block)
|
82
|
+
toy = method_name.to_s
|
79
83
|
if Duplo.can_build? toy
|
80
84
|
Duplo.build toy, *arguments, &block
|
81
85
|
else
|
data/spec/duplo_spec.rb
CHANGED
@@ -3,8 +3,10 @@ require "spec_helper"
|
|
3
3
|
describe Duplo do
|
4
4
|
|
5
5
|
let(:default_size) { Duplo.default_size }
|
6
|
+
let(:valid_bricks) { %w[a aa s ss h hh a0 a1h a2s33h44] }
|
7
|
+
let(:invalid_bricks) { %w[A n 0 11 1s a2s33t44] }
|
6
8
|
|
7
|
-
|
9
|
+
it "has a version number" do
|
8
10
|
expect(Duplo::VERSION).not_to be nil
|
9
11
|
end
|
10
12
|
|
@@ -15,10 +17,21 @@ describe Duplo do
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
describe ".
|
19
|
-
|
20
|
-
|
20
|
+
describe ".respond_to?" do
|
21
|
+
it "returns true for valid bricks" do
|
22
|
+
valid_bricks.each do |brick|
|
23
|
+
expect(Duplo.respond_to? brick).to be true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false for invalid bricks" do
|
28
|
+
invalid_bricks.each do |brick|
|
29
|
+
expect(Duplo.respond_to? brick).to be false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
21
33
|
|
34
|
+
describe ".can_build?" do
|
22
35
|
it "can build valid bricks" do
|
23
36
|
valid_bricks.each do |brick|
|
24
37
|
expect(Duplo.can_build? brick).to be true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duplo
|
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
|
- Nikola Topalović
|
@@ -11,34 +11,34 @@ cert_chain: []
|
|
11
11
|
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '10.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '10.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
description:
|
40
|
+
version: '3.2'
|
41
|
+
description: Generate nested collections with minimum effort.
|
42
42
|
email:
|
43
43
|
- nikola.topalovic@gmail.com
|
44
44
|
executables: []
|
@@ -74,7 +74,7 @@ rubyforge_project:
|
|
74
74
|
rubygems_version: 2.4.5
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
|
-
summary:
|
77
|
+
summary: Generate nested collections with minimum effort.
|
78
78
|
test_files:
|
79
79
|
- spec/duplo_spec.rb
|
80
80
|
has_rdoc:
|