danica 2.7.4 → 2.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +28 -0
- data/.gitignore +6 -1
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +100 -0
- data/Dockerfile +26 -0
- data/Gemfile +2 -1
- data/Rakefile +4 -0
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.rb +13 -0
- data/config/yardstick.yml +33 -0
- data/danica.gemspec +14 -7
- data/docker-compose.yml +14 -9
- data/lib/danica.rb +2 -1
- data/lib/danica/base_operations.rb +2 -0
- data/lib/danica/builder.rb +2 -0
- data/lib/danica/common.rb +5 -2
- data/lib/danica/dsl.rb +8 -6
- data/lib/danica/dsl/builder.rb +3 -1
- data/lib/danica/equation.rb +3 -3
- data/lib/danica/equation/builder.rb +2 -0
- data/lib/danica/exception.rb +3 -2
- data/lib/danica/expressable.rb +14 -8
- data/lib/danica/expression.rb +4 -2
- data/lib/danica/expression/gauss.rb +5 -5
- data/lib/danica/formatted.rb +4 -2
- data/lib/danica/function.rb +5 -3
- data/lib/danica/function/name.rb +2 -0
- data/lib/danica/operator.rb +12 -9
- data/lib/danica/operator/addition.rb +4 -3
- data/lib/danica/operator/chained.rb +4 -3
- data/lib/danica/operator/cos.rb +2 -1
- data/lib/danica/operator/division.rb +2 -1
- data/lib/danica/operator/exponential.rb +2 -1
- data/lib/danica/operator/functional.rb +3 -2
- data/lib/danica/operator/multiplication.rb +4 -2
- data/lib/danica/operator/power.rb +4 -3
- data/lib/danica/operator/sin.rb +2 -1
- data/lib/danica/operator/squared_root.rb +2 -1
- data/lib/danica/variables_holder.rb +7 -4
- data/lib/danica/variables_holder/alias_builder.rb +4 -4
- data/lib/danica/variables_holder/calculator.rb +2 -0
- data/lib/danica/variables_holder/store.rb +3 -2
- data/lib/danica/variables_holder/variables_builder.rb +2 -1
- data/lib/danica/version.rb +3 -1
- data/lib/danica/wrapper.rb +11 -9
- data/lib/danica/wrapper/constant.rb +9 -14
- data/lib/danica/wrapper/container.rb +2 -3
- data/lib/danica/wrapper/group.rb +2 -2
- data/lib/danica/wrapper/negative.rb +2 -1
- data/lib/danica/wrapper/number.rb +4 -3
- data/lib/danica/wrapper/plus_minus.rb +2 -1
- data/lib/danica/wrapper/variable.rb +10 -8
- data/scripts/check_readme.sh +6 -0
- data/scripts/rubycritic.sh +10 -0
- data/spec/integration/global/danica/formatted_spec.rb +87 -0
- data/spec/integration/global/danica/operator/addition_spec.rb +32 -0
- data/spec/integration/{multiplication_spec.rb → global/danica/operator/multiplication_spec.rb} +12 -9
- data/spec/integration/{power_spec.rb → global/danica/operator/power_spec.rb} +4 -2
- data/spec/integration/{negative_spec.rb → global/danica/wrapper/negative_spec.rb} +9 -8
- data/spec/integration/{plus_minus_spec.rb → global/danica/wrapper/plus_minus_spec.rb} +5 -4
- data/spec/integration/readme/constant_spec.rb +4 -1
- data/spec/integration/readme/danica/formatted_spec.rb +24 -0
- data/spec/integration/readme/danica_spec.rb +20 -4
- data/spec/integration/readme/equation_spec.rb +4 -2
- data/spec/integration/readme/expression_spec.rb +11 -8
- data/spec/integration/readme/function_spec.rb +11 -7
- data/spec/integration/readme/number_spec.rb +9 -8
- data/spec/integration/readme/operator_spec.rb +3 -1
- data/spec/integration/readme/variables_spec.rb +8 -6
- data/spec/lib/danica/common_spec.rb +23 -9
- data/spec/lib/danica/dsl_spec.rb +5 -2
- data/spec/lib/danica/equation_spec.rb +10 -8
- data/spec/lib/danica/expressable_spec.rb +5 -2
- data/spec/lib/danica/expression/gauss_spec.rb +6 -3
- data/spec/lib/danica/expression_spec.rb +48 -26
- data/spec/lib/danica/formatted_spec.rb +20 -14
- data/spec/lib/danica/function/name_spec.rb +3 -1
- data/spec/lib/danica/function_spec.rb +14 -10
- data/spec/lib/danica/operator/addition_spec.rb +16 -15
- data/spec/lib/danica/operator/cos_spec.rb +9 -8
- data/spec/lib/danica/operator/division_spec.rb +18 -17
- data/spec/lib/danica/operator/exponential_spec.rb +9 -8
- data/spec/lib/danica/operator/multiplication_spec.rb +16 -15
- data/spec/lib/danica/operator/power_spec.rb +17 -16
- data/spec/lib/danica/operator/sin_spec.rb +9 -8
- data/spec/lib/danica/operator/squared_root_spec.rb +9 -8
- data/spec/lib/danica/operator_spec.rb +13 -4
- data/spec/lib/danica/variables_holder/store_spec.rb +19 -13
- data/spec/lib/danica/variables_holder_spec.rb +76 -59
- data/spec/lib/danica/wrapper/constant_spec.rb +9 -2
- data/spec/lib/danica/wrapper/group_spec.rb +4 -1
- data/spec/lib/danica/wrapper/negative_spec.rb +4 -1
- data/spec/lib/danica/wrapper/number_spec.rb +8 -3
- data/spec/lib/danica/wrapper/plus_minus_spec.rb +4 -1
- data/spec/lib/danica/wrapper/variable_spec.rb +6 -3
- data/spec/lib/danica/wrapper_spec.rb +14 -12
- data/spec/lib/danica_spec.rb +6 -5
- data/spec/spec_helper.rb +2 -1
- data/spec/support/models/expression/baskara.rb +3 -3
- data/spec/support/models/expression/parabole.rb +2 -0
- data/spec/support/models/expression/quadratic_sum.rb +3 -1
- data/spec/support/models/expression/spatial.rb +2 -1
- data/spec/support/models/function/my_function.rb +3 -1
- data/spec/support/models/function/parabole.rb +1 -1
- data/spec/support/models/function/quadratic_sum.rb +2 -0
- data/spec/support/models/function/spatial.rb +2 -0
- data/spec/support/models/operator/inverse.rb +3 -1
- data/spec/support/models/operator/my_operator.rb +3 -1
- data/spec/support/models/variables_holder/dummy.rb +3 -1
- data/spec/support/shared_contexts/common.rb +4 -2
- data/spec/support/shared_examples/base_operations.rb +7 -4
- data/spec/support/shared_examples/common.rb +3 -1
- data/spec/support/shared_examples/operator/chained.rb +12 -6
- data/spec/support/shared_examples/operator/dual_term.rb +9 -8
- data/spec/support/shared_examples/operator/single_input.rb +7 -2
- data/spec/support/shared_examples/variable.rb +8 -4
- metadata +109 -30
- data/spec/integration/addition_spec.rb +0 -28
- data/spec/integration/formatted_spec.rb +0 -75
- data/spec/integration/readme/formatting_spec.rb +0 -34
data/lib/danica/exception.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Danica::Exception < RuntimeError
|
2
4
|
class NotDefined < self; end
|
3
5
|
class FormattedNotFound < self; end
|
4
6
|
class NotImplemented < self; end
|
@@ -14,4 +16,3 @@ class Danica::Exception < ::Exception
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
|
data/lib/danica/expressable.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
|
-
module Expressable
|
4
|
+
module Expressable
|
5
|
+
extend ::ActiveSupport::Concern
|
3
6
|
include VariablesHolder
|
4
7
|
|
5
8
|
class_methods do
|
6
9
|
def built_with(block_name)
|
7
|
-
|
10
|
+
delegate :to, :to_f, to: block_name
|
8
11
|
|
9
|
-
|
12
|
+
define_singleton_method(:build) do |*vars, &block|
|
10
13
|
Class.new(self) do
|
11
14
|
variables(*vars)
|
12
15
|
|
13
16
|
private
|
14
17
|
|
15
|
-
module_eval
|
16
|
-
|
17
|
-
|
18
|
+
module_eval do
|
19
|
+
define_method block_name do
|
20
|
+
instance_variable_get("@#{block_name}") ||
|
21
|
+
block && instance_variable_set("@#{block_name}", instance_eval(&block))
|
22
|
+
end
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
|
-
|
27
|
+
define_singleton_method(:create) do |*vars, &block|
|
22
28
|
build(*vars, &block).new
|
23
29
|
end
|
24
30
|
end
|
@@ -30,7 +36,7 @@ module Danica
|
|
30
36
|
attributes = { variables: args.flatten }.merge(options)
|
31
37
|
|
32
38
|
attributes.each do |key, value|
|
33
|
-
|
39
|
+
public_send("#{key}=", value)
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
data/lib/danica/expression.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Expression
|
5
|
+
autoload :Gauss, 'danica/expression/gauss'
|
6
|
+
|
3
7
|
include Common
|
4
8
|
include DSL
|
5
9
|
include BaseOperations
|
6
10
|
include Expressable
|
7
11
|
|
8
|
-
autoload :Gauss, 'danica/expression/gauss'
|
9
|
-
|
10
12
|
delegate :is_grouped?, :priority, to: :expression_block
|
11
13
|
|
12
14
|
built_with(:expression_block)
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Expression::Gauss < Expression.build(:x, average: { latex: '\mu', gnuplot: :u }, variance_root: { latex: '\sigma', gnuplot: :v }) { num(1) / denominator * exponential(exp) }
|
3
|
-
|
4
5
|
private
|
5
6
|
|
6
7
|
def denominator
|
@@ -9,14 +10,13 @@ module Danica
|
|
9
10
|
|
10
11
|
def exp
|
11
12
|
- (
|
12
|
-
((x - average)
|
13
|
+
((x - average)**2) /
|
13
14
|
(num(2) * variance)
|
14
|
-
|
15
|
+
)
|
15
16
|
end
|
16
17
|
|
17
18
|
def variance
|
18
|
-
@variance ||= variance_root
|
19
|
+
@variance ||= variance_root**2
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
22
|
-
|
data/lib/danica/formatted.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Danica::Formatted
|
2
4
|
attr_reader :content, :options
|
3
5
|
|
@@ -12,8 +14,8 @@ class Danica::Formatted
|
|
12
14
|
|
13
15
|
def ==(other)
|
14
16
|
return false unless other.class == self.class
|
15
|
-
|
16
|
-
|
17
|
+
other.content == content &&
|
18
|
+
other.format == format
|
17
19
|
end
|
18
20
|
|
19
21
|
def format
|
data/lib/danica/function.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Function
|
5
|
+
autoload :Name, 'danica/function/name'
|
6
|
+
|
3
7
|
include VariablesHolder
|
4
8
|
include DSL
|
5
9
|
include Expressable
|
6
10
|
|
7
|
-
|
8
|
-
attr_accessor :name
|
11
|
+
attr_writer :name
|
9
12
|
|
10
13
|
built_with(:function_block)
|
11
14
|
|
@@ -24,4 +27,3 @@ module Danica
|
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
27
|
-
|
data/lib/danica/function/name.rb
CHANGED
data/lib/danica/operator.rb
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Operator
|
3
5
|
include VariablesHolder
|
4
|
-
include BaseOperations
|
5
|
-
|
6
|
-
default_value :priority, 4
|
7
|
-
default_value :is_grouped?, false
|
8
|
-
|
9
|
-
def ==(other)
|
10
|
-
return false unless other.class == self.class
|
11
|
-
variables == other.variables
|
12
|
-
end
|
13
6
|
|
14
7
|
autoload :Functional, 'danica/operator/functional'
|
15
8
|
autoload :Chained, 'danica/operator/chained'
|
@@ -21,5 +14,15 @@ module Danica
|
|
21
14
|
autoload :Sin, 'danica/operator/sin'
|
22
15
|
autoload :SquaredRoot, 'danica/operator/squared_root'
|
23
16
|
autoload :Exponential, 'danica/operator/exponential'
|
17
|
+
|
18
|
+
include BaseOperations
|
19
|
+
|
20
|
+
default_value :priority, 4
|
21
|
+
default_value :is_grouped?, false
|
22
|
+
|
23
|
+
def ==(other)
|
24
|
+
return false unless other.class == self.class
|
25
|
+
variables == other.variables
|
26
|
+
end
|
24
27
|
end
|
25
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Operator::Addition < Operator::Chained
|
3
5
|
default_value :priority, 1
|
@@ -6,8 +8,8 @@ module Danica
|
|
6
8
|
|
7
9
|
default_value :symbol, :+
|
8
10
|
|
9
|
-
def chain_operation(
|
10
|
-
|
11
|
+
def chain_operation(first, second)
|
12
|
+
first + second
|
11
13
|
end
|
12
14
|
|
13
15
|
def join_proc(symbol)
|
@@ -17,4 +19,3 @@ module Danica
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Operator
|
3
5
|
class Chained < Operator
|
@@ -46,11 +48,10 @@ module Danica
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def chain(numbers)
|
49
|
-
numbers.inject do |a,b|
|
50
|
-
chain_operation(a,b)
|
51
|
+
numbers.inject do |a, b|
|
52
|
+
chain_operation(a, b)
|
51
53
|
end.to_f
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
56
|
-
|
data/lib/danica/operator/cos.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Operator::Functional < Operator
|
3
5
|
variables :value
|
@@ -9,7 +11,7 @@ module Danica
|
|
9
11
|
gnu = text if gnu.nil?
|
10
12
|
|
11
13
|
Class.new(self) do
|
12
|
-
module_eval(%
|
14
|
+
module_eval(%(
|
13
15
|
def to_f
|
14
16
|
Math.#{operator}(value.to_f)
|
15
17
|
end
|
@@ -26,4 +28,3 @@ module Danica
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
29
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Operator::Multiplication < Operator::Chained
|
3
5
|
default_value :priority, 3
|
@@ -7,8 +9,8 @@ module Danica
|
|
7
9
|
default_value :tex_symbol, '\cdot'
|
8
10
|
default_value :gnu_symbol, :*
|
9
11
|
|
10
|
-
def chain_operation(
|
11
|
-
|
12
|
+
def chain_operation(first, second)
|
13
|
+
first * second
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class Operator::Power < Operator
|
3
5
|
variables :base, :exponent
|
4
6
|
default_value :is_grouped?, false
|
5
7
|
|
6
8
|
def to_f
|
7
|
-
base.to_f
|
9
|
+
base.to_f**exponent.to_f
|
8
10
|
end
|
9
11
|
|
10
12
|
def to_tex(**options)
|
@@ -12,8 +14,7 @@ module Danica
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def to_gnu(**options)
|
15
|
-
"#{
|
17
|
+
"#{wrap_as_group(base).to_gnu(options)}**(#{exponent.to_gnu(options)})"
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
|
-
|
data/lib/danica/operator/sin.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
|
2
|
-
module VariablesHolder extend ::ActiveSupport::Concern
|
3
|
-
include Common
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
3
|
+
module Danica
|
4
|
+
module VariablesHolder
|
5
5
|
autoload :VariablesBuilder, 'danica/variables_holder/variables_builder'
|
6
6
|
autoload :AliasBuilder, 'danica/variables_holder/alias_builder'
|
7
7
|
autoload :Calculator, 'danica/variables_holder/calculator'
|
8
8
|
autoload :Store, 'danica/variables_holder/store'
|
9
9
|
|
10
|
+
extend ::ActiveSupport::Concern
|
11
|
+
include Common
|
12
|
+
|
10
13
|
delegate :containers_hash, :containers, :variables,
|
11
14
|
:variables_hash, :variables_value_hash,
|
12
15
|
:extract_variables, to: :store
|
13
16
|
|
14
17
|
included do
|
15
|
-
default_value :variable_holder?,
|
18
|
+
default_value :variable_holder?, true
|
16
19
|
end
|
17
20
|
|
18
21
|
class_methods do
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica::VariablesHolder
|
2
4
|
class AliasBuilder
|
3
|
-
|
4
5
|
attr_reader :clazz, :origin, :destiny
|
5
6
|
|
6
7
|
def initialize(origin, destiny, clazz)
|
@@ -11,10 +12,9 @@ module Danica::VariablesHolder
|
|
11
12
|
|
12
13
|
def build
|
13
14
|
clazz.variables_hash.change_keys! { |k| k == origin ? destiny : k }
|
14
|
-
VariablesBuilder.new([
|
15
|
+
VariablesBuilder.new([destiny], clazz).build
|
15
16
|
clazz.send(:alias_method, "#{origin}=", "#{destiny}=")
|
16
17
|
clazz.send(:alias_method, origin, destiny)
|
17
|
-
end
|
18
|
+
end
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
class VariablesHolder::Store
|
3
5
|
attr_reader :default_variables_hash, :variables_names
|
@@ -37,7 +39,7 @@ module Danica
|
|
37
39
|
|
38
40
|
def named_variables_hash
|
39
41
|
variable_variables.inject({}) do |hash, (key, container)|
|
40
|
-
hash.merge(
|
42
|
+
hash.merge((container.content.name || key).to_sym => container)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -64,4 +66,3 @@ module Danica
|
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
67
|
-
|
data/lib/danica/version.rb
CHANGED
data/lib/danica/wrapper.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danica
|
2
4
|
module Wrapper
|
5
|
+
autoload :Number, 'danica/wrapper/number'
|
6
|
+
autoload :Group, 'danica/wrapper/group'
|
7
|
+
autoload :Negative, 'danica/wrapper/negative'
|
8
|
+
autoload :PlusMinus, 'danica/wrapper/plus_minus'
|
9
|
+
autoload :Constant, 'danica/wrapper/constant'
|
10
|
+
autoload :Variable, 'danica/wrapper/variable'
|
11
|
+
autoload :Container, 'danica/wrapper/container'
|
12
|
+
|
3
13
|
def wrap_value(value)
|
4
14
|
Wrapper.wrap_value(value)
|
5
15
|
end
|
@@ -26,16 +36,8 @@ module Danica
|
|
26
36
|
end
|
27
37
|
|
28
38
|
def self.wrap_hash(hash)
|
29
|
-
return Constant.new(hash) if hash.keys.map(&:to_sym).sort == %i
|
39
|
+
return Constant.new(hash) if hash.keys.map(&:to_sym).sort == %i[gnuplot latex value]
|
30
40
|
Variable.new(hash)
|
31
41
|
end
|
32
|
-
|
33
|
-
autoload :Number, 'danica/wrapper/number'
|
34
|
-
autoload :Group, 'danica/wrapper/group'
|
35
|
-
autoload :Negative, 'danica/wrapper/negative'
|
36
|
-
autoload :PlusMinus, 'danica/wrapper/plus_minus'
|
37
|
-
autoload :Constant, 'danica/wrapper/constant'
|
38
|
-
autoload :Variable, 'danica/wrapper/variable'
|
39
|
-
autoload :Container, 'danica/wrapper/container'
|
40
42
|
end
|
41
43
|
end
|