venn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/venn.rb +5 -0
- data/lib/venn/diagram.rb +65 -0
- data/lib/venn/version.rb +3 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/venn/diagram_spec.rb +155 -0
- data/venn.gemspec +24 -0
- metadata +113 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Darren Cauthon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Venn
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'venn'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install venn
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/venn.rb
ADDED
data/lib/venn/diagram.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Venn
|
2
|
+
class Diagram
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@values = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(meth, *args, &blk)
|
9
|
+
if meth[-3, 3] == '_is'
|
10
|
+
id = meth[0, meth.length - 3]
|
11
|
+
value = args[0]
|
12
|
+
set_single_value id, value
|
13
|
+
elsif meth[-4, 4] == '_are'
|
14
|
+
id = meth[0, meth.length - 4]
|
15
|
+
value = args[0]
|
16
|
+
set_single_value id, value
|
17
|
+
elsif meth[-5, 5] == '_only'
|
18
|
+
id = meth[0, meth.length - 5]
|
19
|
+
find_exclusive_values_in id
|
20
|
+
else
|
21
|
+
ins = meth.to_s.split('_and_')
|
22
|
+
find_the_and_matches ins
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def set_single_value id, value
|
29
|
+
@values[id] = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_exclusive_values_in id
|
33
|
+
@values[id].select do |value|
|
34
|
+
@values.keys.select { |k| k != id }.
|
35
|
+
select { |key| is_in?(value, key) }.count == 0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_the_and_matches(ins)
|
40
|
+
outs = @values.keys.select { |x| ins.include?(x) == false }
|
41
|
+
matches = @values[ins.first].select do |x|
|
42
|
+
ins.select do |i|
|
43
|
+
@values[i].include? x
|
44
|
+
end.count == ins.count
|
45
|
+
end
|
46
|
+
matches.select do |x|
|
47
|
+
outs.select do |o|
|
48
|
+
@values[o].include?(x)
|
49
|
+
end.count == 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_in?(value, key)
|
54
|
+
@values[key].include? value
|
55
|
+
rescue
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
59
|
+
def is_not_in?(value, key)
|
60
|
+
@values[key].include?(value) == false
|
61
|
+
rescue
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/venn/version.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Venn::Diagram do
|
4
|
+
|
5
|
+
let(:diagram) { Venn::Diagram.new }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Venn::Diagram.nil?.must_equal false
|
9
|
+
end
|
10
|
+
|
11
|
+
[:a, :b].to_objects {[
|
12
|
+
[[1, 2], [3, 4]],
|
13
|
+
[[5, 6], [7, 8]]
|
14
|
+
]}.each do |test|
|
15
|
+
describe "no match" do
|
16
|
+
before do
|
17
|
+
diagram.a_is test.a
|
18
|
+
diagram.b_is test.b
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return set a" do
|
22
|
+
diagram.a_only.must_equal test.a
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return set b" do
|
26
|
+
diagram.b_only.must_equal test.b
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return nothing for a and b" do
|
30
|
+
diagram.a_and_b.must_equal []
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
[:a, :b, :a_only, :b_only, :a_and_b].to_objects {[
|
36
|
+
[[1, 2], [2, 3], [1], [3], [2]],
|
37
|
+
[['a', 'b'], ['b', 'c'], ['a'], ['c'], ['b']]
|
38
|
+
]}.each do |test|
|
39
|
+
describe "one match" do
|
40
|
+
before do
|
41
|
+
diagram.a_is test.a
|
42
|
+
diagram.b_is test.b
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a" do
|
46
|
+
diagram.a_only.must_equal test.a_only
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return b" do
|
50
|
+
diagram.b_only.must_equal test.b_only
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return the one match for a and b" do
|
54
|
+
diagram.a_and_b.must_equal test.a_and_b
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "three sets of data with a few matches" do
|
60
|
+
describe "first example" do
|
61
|
+
before do
|
62
|
+
diagram.a_is ['abc', 'ab', 'ac', 'a']
|
63
|
+
diagram.b_is ['abc', 'ab', 'bc', 'b']
|
64
|
+
diagram.c_is ['abc', 'bc', 'ac', 'c']
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return a" do
|
68
|
+
diagram.a_only.must_equal ['a']
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return b" do
|
72
|
+
diagram.b_only.must_equal ['b']
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return c" do
|
76
|
+
diagram.c_only.must_equal ['c']
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return a and b" do
|
80
|
+
diagram.a_and_b.must_equal ['ab']
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return b and c" do
|
84
|
+
diagram.b_and_c.must_equal ['bc']
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return a and c" do
|
88
|
+
diagram.a_and_c.must_equal ['ac']
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return a and b and c" do
|
92
|
+
diagram.a_and_b_and_c.must_equal ['abc']
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "second example" do
|
97
|
+
before do
|
98
|
+
diagram.a_is ['xyz', 'xy', 'xz', 'x']
|
99
|
+
diagram.b_is ['xyz', 'xy', 'yz', 'y']
|
100
|
+
diagram.c_is ['xyz', 'yz', 'xz', 'z']
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return a" do
|
104
|
+
diagram.a_only.must_equal ['x']
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return b" do
|
108
|
+
diagram.b_only.must_equal ['y']
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return c" do
|
112
|
+
diagram.c_only.must_equal ['z']
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return a and b" do
|
116
|
+
diagram.a_and_b.must_equal ['xy']
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return b and c" do
|
120
|
+
diagram.b_and_c.must_equal ['yz']
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return a and c" do
|
124
|
+
diagram.a_and_c.must_equal ['xz']
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return a and b and c" do
|
128
|
+
diagram.a_and_b_and_c.must_equal ['xyz']
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "setting values with are" do
|
134
|
+
before do
|
135
|
+
diagram.a_are ['a']
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should have set the value" do
|
139
|
+
diagram.a_only.must_equal ['a']
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "setting values with more than one letter" do
|
144
|
+
before do
|
145
|
+
diagram.good_items_are ['a', 'b']
|
146
|
+
diagram.bad_items_are ['b', 'c']
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should have set the value" do
|
150
|
+
diagram.good_items_only.must_equal ['a']
|
151
|
+
diagram.bad_items_only.must_equal ['c']
|
152
|
+
diagram.good_items_and_bad_items.must_equal ['b']
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/venn.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'venn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "venn"
|
8
|
+
spec.version = Venn::VERSION
|
9
|
+
spec.authors = ["Darren Cauthon"]
|
10
|
+
spec.email = ["darren@cauthon.com"]
|
11
|
+
spec.description = %q{Simple venn diagrams}
|
12
|
+
spec.summary = %q{Simple venn diagrams}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "subtle"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: venn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Darren Cauthon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: subtle
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Simple venn diagrams
|
63
|
+
email:
|
64
|
+
- darren@cauthon.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/venn.rb
|
75
|
+
- lib/venn/diagram.rb
|
76
|
+
- lib/venn/version.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/venn/diagram_spec.rb
|
79
|
+
- venn.gemspec
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: 4456186537701495947
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: 4456186537701495947
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.24
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Simple venn diagrams
|
111
|
+
test_files:
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/venn/diagram_spec.rb
|