chainedexpressions 0.1
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 +7 -0
- data/lib/chainedexpressions/chainedexpressions.rb +56 -0
- data/lib/chainedexpressions/version.rb +13 -0
- data/lib/chainedexpressions.rb +12 -0
- data/spec/chainedexpressions_spec.rb +48 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03d2e6aa14ad8c7c968a25d8d89fb491dbf317ec
|
4
|
+
data.tar.gz: 53412ed7ee3a9dbf331b3d4da92c3ee386403966
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: faff82af13f72f60c98048296974c9a3e0927512cbdc7415a76530c1fe59d836bbbf48eba26b4280908b791c18fae32c2079657efa88b38209cbbe3034f601a0
|
7
|
+
data.tar.gz: 15d54631aa7d0bb5c3efd90936844bd09a103f0094c6673de1a5a87e4a7edcadafa5202914459862c52f93edeae1274321e601df6ade84b5e63c87fd08eebb69
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module ChainedExpressions
|
12
|
+
$operators = {
|
13
|
+
:< => :lt,
|
14
|
+
:<= => :lte,
|
15
|
+
:>= => :gte,
|
16
|
+
:> => :gt,
|
17
|
+
}
|
18
|
+
|
19
|
+
%w(TrueClass FalseClass).each { |c|
|
20
|
+
eval <<-EOM
|
21
|
+
refine #{c} do
|
22
|
+
$operators.each { |k, o|
|
23
|
+
define_method(o) do |*exp|
|
24
|
+
$f.exp_true? k, exp.first
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method k, o
|
28
|
+
}
|
29
|
+
end
|
30
|
+
EOM
|
31
|
+
}
|
32
|
+
|
33
|
+
refine Fixnum do
|
34
|
+
def exp_true?(op, n)
|
35
|
+
case op
|
36
|
+
when :< then (self <=> n) == -1
|
37
|
+
when :<= then (self <=> n) == -1 || (self <=> n) == 0
|
38
|
+
when :>= then (self <=> n) == 0 || (self <=> n) == 1
|
39
|
+
when :> then (self <=> n) == 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
$operators.each { |k, o|
|
44
|
+
define_method(o) do |*exp|
|
45
|
+
exp.each { |n|
|
46
|
+
$f = n
|
47
|
+
return false unless self.exp_true? k, n
|
48
|
+
}
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method k, o
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module ChainedExpressions
|
12
|
+
VERSION = '0.1'
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
require 'chainedexpressions/chainedexpressions'
|
12
|
+
require 'chainedexpressions/version'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
require 'rspec'
|
12
|
+
require 'chainedexpressions'
|
13
|
+
|
14
|
+
using ChainedExpressions
|
15
|
+
|
16
|
+
describe ChainedExpressions do
|
17
|
+
it 'can evaluate true expressions' do
|
18
|
+
(20 < 25).should be true
|
19
|
+
|
20
|
+
(20 < 25 < 30).should be true
|
21
|
+
(20 < 25 < 30).should be true
|
22
|
+
|
23
|
+
(20 <= 25 <= 30 <= 30 <= 35).should be true
|
24
|
+
(20 <= 25 <= 30 <= 30 <= 35).should be true
|
25
|
+
|
26
|
+
(35 > 30 > 25 > 20).should be true
|
27
|
+
(35 > 30 > 25 > 20).should be true
|
28
|
+
|
29
|
+
(35 >= 30 >= 30 >= 25 >= 20).should be true
|
30
|
+
(35 >= 30 >= 30 >= 25 >= 20).should be true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can evaluate false expressions' do
|
34
|
+
(30 < 25).should be false
|
35
|
+
|
36
|
+
(30 < 25 < 20).should be false
|
37
|
+
(30 < 25 < 20).should be false
|
38
|
+
|
39
|
+
(35 <= 30 <= 30 <= 25 <= 20).should be false
|
40
|
+
(35 <= 30 <= 30 <= 25 <= 20).should be false
|
41
|
+
|
42
|
+
(20 > 25 > 30 > 35).should be false
|
43
|
+
(20 > 25 > 30 > 35).should be false
|
44
|
+
|
45
|
+
(20 >= 25 >= 30 >= 30 >= 35).should be false
|
46
|
+
(20 >= 25 >= 30 >= 30 >= 35).should be false
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chainedexpressions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Capuano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Implement chained expressions in ruby
|
42
|
+
email: webmaster@giovannicapuano.net
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/chainedexpressions/chainedexpressions.rb
|
48
|
+
- lib/chainedexpressions/version.rb
|
49
|
+
- lib/chainedexpressions.rb
|
50
|
+
- spec/chainedexpressions_spec.rb
|
51
|
+
homepage: https://github.com/RoxasShadow
|
52
|
+
licenses:
|
53
|
+
- WTFPL
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.0.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Chained expressions in ruby
|
75
|
+
test_files:
|
76
|
+
- spec/chainedexpressions_spec.rb
|