dentaku 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,6 +36,23 @@ evaluate expressions against those stored values:
36
36
 
37
37
  For maximum CS geekery, `bind` is an alias of `store`.
38
38
 
39
+ Dentaku understands precedence order and using parentheses to group expressions
40
+ to ensure proper evaluation:
41
+
42
+ calculator.evaluate('5 + 3 * 2')
43
+ => 11
44
+ calculator.evaluate('(5 + 3) * 2')
45
+ => 16
46
+
47
+ A number of functions are also supported. Okay, the number is currently one,
48
+ but more will be added soon. The current function is `if`, which works like
49
+ Excel's `if`:
50
+
51
+ calculator.evaluate('if (pears < 10, 10, 20)', :pears => 5)
52
+ => 10
53
+ calculator.evaluate('if (pears < 10, 10, 20)', :pears => 15)
54
+ => 20
55
+
39
56
  If you're too lazy to be building calculator objects, there's a shortcut just
40
57
  for you:
41
58
 
@@ -100,12 +100,12 @@ module Dentaku
100
100
  end
101
101
 
102
102
  def if(*args)
103
- _, open, cond, _, true_value, _, false_value, close = args
103
+ _, open, condition, _, true_value, _, false_value, close = args
104
104
 
105
- if evaluate_token_stream([cond])
106
- evaluate_token_stream([true_value])
105
+ if condition.value
106
+ true_value
107
107
  else
108
- evaluate_token_stream([false_value])
108
+ false_value
109
109
  end
110
110
  end
111
111
  end
@@ -1,3 +1,3 @@
1
1
  module Dentaku
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -52,7 +52,8 @@ describe Dentaku::Calculator do
52
52
 
53
53
  describe 'functions' do
54
54
  it 'should include IF' do
55
- calculator.evaluate('if (foo < 10, 10, 20)', :foo => 2).should eq(10)
55
+ calculator.evaluate('if (foo < 8, 10, 20)', :foo => 2).should eq(10)
56
+ calculator.evaluate('if (foo < 8, 10, 20)', :foo => 9).should eq(20)
56
57
  end
57
58
  end
58
59
  end
metadata CHANGED
@@ -1,47 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dentaku
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Solomon White
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-24 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70323614305400 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- description: " Dentaku is a parser and evaluator for mathematical formulas\n"
36
- email:
23
+ prerelease: false
24
+ version_requirements: *70323614305400
25
+ description: ! ' Dentaku is a parser and evaluator for mathematical formulas
26
+
27
+ '
28
+ email:
37
29
  - rubysolo@gmail.com
38
30
  executables: []
39
-
40
31
  extensions: []
41
-
42
32
  extra_rdoc_files: []
43
-
44
- files:
33
+ files:
45
34
  - .gitignore
46
35
  - Gemfile
47
36
  - README.md
@@ -62,41 +51,31 @@ files:
62
51
  - spec/token_scanner_spec.rb
63
52
  - spec/token_spec.rb
64
53
  - spec/tokenizer_spec.rb
65
- has_rdoc: true
66
54
  homepage: http://github.com/rubysolo/dentaku
67
55
  licenses: []
68
-
69
56
  post_install_message:
70
57
  rdoc_options: []
71
-
72
- require_paths:
58
+ require_paths:
73
59
  - lib
74
- required_ruby_version: !ruby/object:Gem::Requirement
60
+ required_ruby_version: !ruby/object:Gem::Requirement
75
61
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
67
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
92
72
  requirements: []
93
-
94
73
  rubyforge_project: dentaku
95
- rubygems_version: 1.3.7
74
+ rubygems_version: 1.8.10
96
75
  signing_key:
97
76
  specification_version: 3
98
77
  summary: A formula language parser and evaluator
99
- test_files:
78
+ test_files:
100
79
  - spec/calculator_spec.rb
101
80
  - spec/dentaku_spec.rb
102
81
  - spec/evaluator_spec.rb