exalted_math 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/exalted_math.gemspec +2 -2
- data/lib/exalted_math/node/named.rb +7 -1
- data/spec/node_spec.rb +15 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/exalted_math.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "exalted_math"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jonathan Stott"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-13"
|
13
13
|
s.description = "Parsing and evaluation of simple maths expressions for Exalted\n\nThis intended to aid in evaluating simple calculations which appear on character sheets, especially for Exalted."
|
14
14
|
s.email = "jonathan.stott@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -13,7 +13,13 @@ module ExaltedMath
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def value(context={})
|
16
|
-
context.fetch
|
16
|
+
if context.respond_to?(:fetch)
|
17
|
+
context.fetch(name) { raise ContextError, name }
|
18
|
+
elsif context.respond_to?(name)
|
19
|
+
context.public_send(name)
|
20
|
+
else
|
21
|
+
raise ContextError, name
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
def ==(o)
|
data/spec/node_spec.rb
CHANGED
@@ -5,6 +5,12 @@ require 'exalted_math/node'
|
|
5
5
|
|
6
6
|
include ExaltedMath
|
7
7
|
|
8
|
+
class Context
|
9
|
+
attr_reader :foo
|
10
|
+
def initialize(foo)
|
11
|
+
@foo = foo
|
12
|
+
end
|
13
|
+
end
|
8
14
|
|
9
15
|
describe "ExaltedMath::Node" do
|
10
16
|
before do
|
@@ -25,6 +31,7 @@ describe "ExaltedMath::Node" do
|
|
25
31
|
@min = Node::Minimum.new([@three, @seven], 1)
|
26
32
|
@max = Node::Maximum.new([@three, @seven], 1 )
|
27
33
|
@context = { 'foo' => 3, 'bar' => 4 }
|
34
|
+
@class_context = Context.new(3)
|
28
35
|
end
|
29
36
|
it "a number is constant" do
|
30
37
|
@three.should.be.constant
|
@@ -117,6 +124,14 @@ describe "ExaltedMath::Node" do
|
|
117
124
|
@bar.value(@context).should == @context['bar']
|
118
125
|
end
|
119
126
|
|
127
|
+
it "allows the use of an object in the context" do
|
128
|
+
@foo.value(@class_context).should == @class_context.foo
|
129
|
+
end
|
130
|
+
|
131
|
+
it "raises an error on a missing context" do
|
132
|
+
lambda { @bar.value(@class_context) }.should.raise(ExaltedMath::ContextError)
|
133
|
+
end
|
134
|
+
|
120
135
|
it "the value of an add is the sum of the two children" do
|
121
136
|
@add.value(@context).should == 10
|
122
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exalted_math
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|