README.md in dentaku-3.0.0 vs README.md in dentaku-3.1.0
- old
+ new
@@ -4,12 +4,13 @@
[](https://gitter.im/rubysolo/dentaku?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](http://badge.fury.io/rb/dentaku)
[](https://travis-ci.org/rubysolo/dentaku)
[](https://codeclimate.com/github/rubysolo/dentaku)
[](https://hakiri.io/github/rubysolo/dentaku)
-[](https://coveralls.io/github/rubysolo/dentaku)
+[](https://codecov.io/gh/rubysolo/dentaku)
+
DESCRIPTION
-----------
Dentaku is a parser and evaluator for a mathematical and logical formula
language that allows run-time binding of values to variables referenced in the
@@ -33,10 +34,20 @@
```ruby
calculator.evaluate('kiwi + 5', kiwi: 2)
#=> 7
```
+To enter a case sensitive mode, just pass an option to the calculator instance:
+
+```ruby
+calculator.evaluate('Kiwi + 5', Kiwi: -2, kiwi: 2)
+#=> 7
+calculator = Dentaku::Calculator.new(case_sensitive: true)
+calculator.evaluate('Kiwi + 5', Kiwi: -2, kiwi: 2)
+#=> 3
+```
+
You can also store the variable values in the calculator's memory and then
evaluate expressions against those stored values:
```ruby
calculator.store(peaches: 15)
@@ -67,15 +78,18 @@
#=> nil
calculator.evaluate!('10 * x')
Dentaku::UnboundVariableError: Dentaku::UnboundVariableError
```
-Dentaku has built-in functions (including `if`, `not`, `min`, `max`, and
+Dentaku has built-in functions (including `if`, `not`, `min`, `max`, `sum`, and
`round`) and the ability to define custom functions (see below). Functions
generally work like their counterparts in Excel:
```ruby
+calculator.evaluate('SUM(1, 1, 2, 3, 5, 8)')
+#=> 20
+
calculator.evaluate('if (pears < 10, 10, 20)', pears: 5)
#=> 10
calculator.evaluate('if (pears < 10, 10, 20)', pears: 15)
#=> 20
```
@@ -130,11 +144,11 @@
Comparison: `<`, `>`, `<=`, `>=`, `<>`, `!=`, `=`,
Logic: `IF`, `AND`, `OR`, `NOT`, `SWITCH`
-Numeric: `MIN`, `MAX`, `ROUND`, `ROUNDDOWN`, `ROUNDUP`
+Numeric: `MIN`, `MAX`, `SUM`, `ROUND`, `ROUNDDOWN`, `ROUNDUP`
Selections: `CASE` (syntax see [spec](https://github.com/rubysolo/dentaku/blob/master/spec/calculator_spec.rb#L292))
String: `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, `CONCAT`, `CONTAINS`
@@ -264,9 +278,36 @@
(However both of these are already built-in -- the `^` operator and the `MAX`
function)
Functions can be added individually using Calculator#add_function, or en masse
using Calculator#add_functions.
+
+FUNCTION ALIASES
+----------------
+
+Every function can be aliased by synonyms. For example, it can be useful if
+your application is multilingual.
+
+```ruby
+Dentaku.aliases = {
+ round: ['rrrrround!', 'округлить']
+}
+
+Dentaku('rrrrround!(8.2) + округлить(8.4)') # the same as round(8.2) + round(8.4)
+# 16
+```
+
+Also, if you need thread-safe aliases you can pass them to `Dentaku::Calculator`
+initializer:
+
+```ruby
+aliases = {
+ round: ['rrrrround!', 'округлить']
+}
+c = Dentaku::Calculator.new(aliases: aliases)
+c.evaluate('rrrrround!(8.2) + округлить(8.4)')
+# 16
+```
THANKS
------
Big thanks to [ElkStone Basements](http://www.elkstonebasements.com/) for