danica 2.5.1 → 2.6.0
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 +4 -4
- data/README.md +11 -8
- data/lib/danica/equation.rb +13 -2
- data/lib/danica/equation/builder.rb +33 -0
- data/lib/danica/function.rb +6 -16
- data/lib/danica/version.rb +1 -1
- data/spec/integration/readme/equation_spec.rb +4 -8
- data/spec/lib/danica/equation_spec.rb +26 -5
- data/spec/lib/danica/function_spec.rb +0 -20
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16850a566b9ec30cc48ed15fbe2db94136cb3365
|
4
|
+
data.tar.gz: 7735a1b8ebb9d70684565bc0f6e3ffbcf6e57ce1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de604b1d39697a6f239d2d623b0f028d40a335584beb2df8df8c9cce80c81ec04775c00f300659bc2d8e5a803d3fb44a00b1a4ad1ddc72cf736456839a8b39e
|
7
|
+
data.tar.gz: 97701eaafa8489ee781e5209482b8784d7443b05a14512dc14e1c239757d9f3521317f8dacb5242bdc808cd1331059629d743ffb3580a6d5ed2449be6ff95f60
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ create gnu or tex output strings to be used on your template
|
|
42
42
|
### Operators
|
43
43
|
Operators represent a matematical operation such as sum, product, sin, etc..
|
44
44
|
|
45
|
-
Operators are to be composed to create an [expression](#expressions), [equation](#
|
45
|
+
Operators are to be composed to create an [expression](#expressions), [equation](#equations) or [function](#functions) (see below)
|
46
46
|
|
47
47
|
```ruby
|
48
48
|
class MyOperator < Danica::Operator
|
@@ -176,13 +176,16 @@ clazz.new.to_tex
|
|
176
176
|
Equations are formed by two expressions with their own variables
|
177
177
|
|
178
178
|
```ruby
|
179
|
-
Danica::Equation.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
179
|
+
Danica::Equation.build(:x, :y, :z) do
|
180
|
+
left { x ** 2 + y ** 2 }
|
181
|
+
right { number(1) - z ** 2 }
|
182
|
+
end.new.to_tex
|
183
|
+
```
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
Danica::Equation.create(:x, :y, :z) do
|
187
|
+
left { x ** 2 + y ** 2 }
|
188
|
+
right { number(1) - z ** 2 }
|
186
189
|
end.to_tex
|
187
190
|
```
|
188
191
|
|
data/lib/danica/equation.rb
CHANGED
@@ -2,16 +2,27 @@ module Danica
|
|
2
2
|
class Equation
|
3
3
|
include Common
|
4
4
|
include VariablesHolder
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
autoload :Builder, 'danica/equation/builder'
|
7
7
|
|
8
8
|
def initialize(*args)
|
9
9
|
self.variables = args.flatten
|
10
10
|
end
|
11
11
|
|
12
|
+
class << self
|
13
|
+
def build(*variables, &block)
|
14
|
+
Builder.new(*variables, &block).build
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(*variables, &block)
|
18
|
+
build(*variables, &block).new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
def to(format)
|
13
23
|
"#{left.to(format)} = #{right.to(format)}"
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
17
27
|
|
28
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Danica
|
2
|
+
class Equation::Builder
|
3
|
+
attr_reader :variables
|
4
|
+
|
5
|
+
def initialize(*variables, &block)
|
6
|
+
@variables = variables
|
7
|
+
instance_eval(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def build
|
11
|
+
vars = variables
|
12
|
+
l = left
|
13
|
+
r = right
|
14
|
+
|
15
|
+
Class.new(Equation) do
|
16
|
+
variables(*vars)
|
17
|
+
|
18
|
+
define_method :left, l
|
19
|
+
define_method :right, r
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def left(&block)
|
24
|
+
@left = block if block_given?
|
25
|
+
@left
|
26
|
+
end
|
27
|
+
|
28
|
+
def right(&block)
|
29
|
+
@right = block if block_given?
|
30
|
+
@right
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/danica/function.rb
CHANGED
@@ -1,32 +1,22 @@
|
|
1
1
|
module Danica
|
2
|
-
class Function
|
2
|
+
class Function
|
3
3
|
include Common
|
4
|
+
include VariablesHolder
|
4
5
|
include DSL
|
5
6
|
include Expressable
|
6
7
|
|
7
8
|
autoload :Name, 'danica/function/name'
|
8
9
|
attr_accessor :name
|
9
10
|
|
10
|
-
reset_variables
|
11
|
-
|
12
11
|
built_with(:function_block)
|
13
12
|
|
14
13
|
def name
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def expression
|
19
|
-
@expression ||= Expression.build(:x) do
|
20
|
-
x
|
21
|
-
end.new(function_block)
|
14
|
+
Name.new(name: @name, variables: containers)
|
22
15
|
end
|
23
16
|
|
24
|
-
def
|
25
|
-
name
|
26
|
-
end
|
27
|
-
|
28
|
-
def right
|
29
|
-
expression
|
17
|
+
def to(*args)
|
18
|
+
"#{name.to(*args)} = #{function_block.to(*args)}"
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
22
|
+
|
data/lib/danica/version.rb
CHANGED
@@ -2,14 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Danica::Equation do
|
4
4
|
subject do
|
5
|
-
described_class.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
equation.right = Danica.build(:x, :z) do
|
10
|
-
number(1) - z ** 2
|
11
|
-
end
|
12
|
-
end
|
5
|
+
described_class.build(:x, :y, :z) do
|
6
|
+
left { x ** 2 + y ** 2 }
|
7
|
+
right { number(1) - z ** 2 }
|
8
|
+
end.new
|
13
9
|
end
|
14
10
|
|
15
11
|
describe '#to_gnu' do
|
@@ -1,14 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Danica::Equation do
|
4
|
-
let(:
|
5
|
-
|
4
|
+
let(:clazz) do
|
5
|
+
described_class.build(:x, :y) do
|
6
|
+
left { y }
|
7
|
+
right { x ** 2 }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
subject do
|
12
|
+
clazz.new
|
6
13
|
end
|
7
|
-
|
8
|
-
|
14
|
+
|
15
|
+
describe '.build' do
|
16
|
+
it 'returns a class that is also an equation' do
|
17
|
+
expect(subject).to be_a(Danica::Equation)
|
18
|
+
end
|
9
19
|
end
|
10
20
|
|
11
|
-
|
21
|
+
describe '.create' do
|
22
|
+
subject do
|
23
|
+
described_class.create(:x, :y) do
|
24
|
+
left { y }
|
25
|
+
right { x ** 2 }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns a class that is also an equation' do
|
30
|
+
expect(subject).to be_a(Danica::Equation)
|
31
|
+
end
|
32
|
+
end
|
12
33
|
|
13
34
|
describe '#to_f' do
|
14
35
|
it do
|
@@ -242,25 +242,5 @@ describe Danica::Function do
|
|
242
242
|
expect(function.to_gnu).to eq('f(2, y) = 2**(y)')
|
243
243
|
end
|
244
244
|
end
|
245
|
-
|
246
|
-
describe '#left' do
|
247
|
-
it 'is an alias for name' do
|
248
|
-
expect(subject.left).to eq(subject.name)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe '#left=' do
|
253
|
-
it 'is an alias for the expression' do
|
254
|
-
expect do
|
255
|
-
subject.left = Danica::Operator::Power.new(:x, 2)
|
256
|
-
end.to change { subject.left.content }
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
describe '#right' do
|
261
|
-
it 'is an alias for the expression' do
|
262
|
-
expect(subject.right).to eq(subject.right)
|
263
|
-
end
|
264
|
-
end
|
265
245
|
end
|
266
246
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/danica/common.rb
|
145
145
|
- lib/danica/dsl.rb
|
146
146
|
- lib/danica/equation.rb
|
147
|
+
- lib/danica/equation/builder.rb
|
147
148
|
- lib/danica/exception.rb
|
148
149
|
- lib/danica/expressable.rb
|
149
150
|
- lib/danica/expression.rb
|