danica 2.7.4 → 2.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +6 -1
  4. data/.rubocop.yml +9 -0
  5. data/.rubocop_todo.yml +100 -0
  6. data/Dockerfile +26 -0
  7. data/Gemfile +2 -1
  8. data/Rakefile +4 -0
  9. data/config/rubycritc.rb +12 -0
  10. data/config/yardstick.rb +13 -0
  11. data/config/yardstick.yml +33 -0
  12. data/danica.gemspec +14 -7
  13. data/docker-compose.yml +14 -9
  14. data/lib/danica.rb +2 -1
  15. data/lib/danica/base_operations.rb +2 -0
  16. data/lib/danica/builder.rb +2 -0
  17. data/lib/danica/common.rb +5 -2
  18. data/lib/danica/dsl.rb +8 -6
  19. data/lib/danica/dsl/builder.rb +3 -1
  20. data/lib/danica/equation.rb +3 -3
  21. data/lib/danica/equation/builder.rb +2 -0
  22. data/lib/danica/exception.rb +3 -2
  23. data/lib/danica/expressable.rb +14 -8
  24. data/lib/danica/expression.rb +4 -2
  25. data/lib/danica/expression/gauss.rb +5 -5
  26. data/lib/danica/formatted.rb +4 -2
  27. data/lib/danica/function.rb +5 -3
  28. data/lib/danica/function/name.rb +2 -0
  29. data/lib/danica/operator.rb +12 -9
  30. data/lib/danica/operator/addition.rb +4 -3
  31. data/lib/danica/operator/chained.rb +4 -3
  32. data/lib/danica/operator/cos.rb +2 -1
  33. data/lib/danica/operator/division.rb +2 -1
  34. data/lib/danica/operator/exponential.rb +2 -1
  35. data/lib/danica/operator/functional.rb +3 -2
  36. data/lib/danica/operator/multiplication.rb +4 -2
  37. data/lib/danica/operator/power.rb +4 -3
  38. data/lib/danica/operator/sin.rb +2 -1
  39. data/lib/danica/operator/squared_root.rb +2 -1
  40. data/lib/danica/variables_holder.rb +7 -4
  41. data/lib/danica/variables_holder/alias_builder.rb +4 -4
  42. data/lib/danica/variables_holder/calculator.rb +2 -0
  43. data/lib/danica/variables_holder/store.rb +3 -2
  44. data/lib/danica/variables_holder/variables_builder.rb +2 -1
  45. data/lib/danica/version.rb +3 -1
  46. data/lib/danica/wrapper.rb +11 -9
  47. data/lib/danica/wrapper/constant.rb +9 -14
  48. data/lib/danica/wrapper/container.rb +2 -3
  49. data/lib/danica/wrapper/group.rb +2 -2
  50. data/lib/danica/wrapper/negative.rb +2 -1
  51. data/lib/danica/wrapper/number.rb +4 -3
  52. data/lib/danica/wrapper/plus_minus.rb +2 -1
  53. data/lib/danica/wrapper/variable.rb +10 -8
  54. data/scripts/check_readme.sh +6 -0
  55. data/scripts/rubycritic.sh +10 -0
  56. data/spec/integration/global/danica/formatted_spec.rb +87 -0
  57. data/spec/integration/global/danica/operator/addition_spec.rb +32 -0
  58. data/spec/integration/{multiplication_spec.rb → global/danica/operator/multiplication_spec.rb} +12 -9
  59. data/spec/integration/{power_spec.rb → global/danica/operator/power_spec.rb} +4 -2
  60. data/spec/integration/{negative_spec.rb → global/danica/wrapper/negative_spec.rb} +9 -8
  61. data/spec/integration/{plus_minus_spec.rb → global/danica/wrapper/plus_minus_spec.rb} +5 -4
  62. data/spec/integration/readme/constant_spec.rb +4 -1
  63. data/spec/integration/readme/danica/formatted_spec.rb +24 -0
  64. data/spec/integration/readme/danica_spec.rb +20 -4
  65. data/spec/integration/readme/equation_spec.rb +4 -2
  66. data/spec/integration/readme/expression_spec.rb +11 -8
  67. data/spec/integration/readme/function_spec.rb +11 -7
  68. data/spec/integration/readme/number_spec.rb +9 -8
  69. data/spec/integration/readme/operator_spec.rb +3 -1
  70. data/spec/integration/readme/variables_spec.rb +8 -6
  71. data/spec/lib/danica/common_spec.rb +23 -9
  72. data/spec/lib/danica/dsl_spec.rb +5 -2
  73. data/spec/lib/danica/equation_spec.rb +10 -8
  74. data/spec/lib/danica/expressable_spec.rb +5 -2
  75. data/spec/lib/danica/expression/gauss_spec.rb +6 -3
  76. data/spec/lib/danica/expression_spec.rb +48 -26
  77. data/spec/lib/danica/formatted_spec.rb +20 -14
  78. data/spec/lib/danica/function/name_spec.rb +3 -1
  79. data/spec/lib/danica/function_spec.rb +14 -10
  80. data/spec/lib/danica/operator/addition_spec.rb +16 -15
  81. data/spec/lib/danica/operator/cos_spec.rb +9 -8
  82. data/spec/lib/danica/operator/division_spec.rb +18 -17
  83. data/spec/lib/danica/operator/exponential_spec.rb +9 -8
  84. data/spec/lib/danica/operator/multiplication_spec.rb +16 -15
  85. data/spec/lib/danica/operator/power_spec.rb +17 -16
  86. data/spec/lib/danica/operator/sin_spec.rb +9 -8
  87. data/spec/lib/danica/operator/squared_root_spec.rb +9 -8
  88. data/spec/lib/danica/operator_spec.rb +13 -4
  89. data/spec/lib/danica/variables_holder/store_spec.rb +19 -13
  90. data/spec/lib/danica/variables_holder_spec.rb +76 -59
  91. data/spec/lib/danica/wrapper/constant_spec.rb +9 -2
  92. data/spec/lib/danica/wrapper/group_spec.rb +4 -1
  93. data/spec/lib/danica/wrapper/negative_spec.rb +4 -1
  94. data/spec/lib/danica/wrapper/number_spec.rb +8 -3
  95. data/spec/lib/danica/wrapper/plus_minus_spec.rb +4 -1
  96. data/spec/lib/danica/wrapper/variable_spec.rb +6 -3
  97. data/spec/lib/danica/wrapper_spec.rb +14 -12
  98. data/spec/lib/danica_spec.rb +6 -5
  99. data/spec/spec_helper.rb +2 -1
  100. data/spec/support/models/expression/baskara.rb +3 -3
  101. data/spec/support/models/expression/parabole.rb +2 -0
  102. data/spec/support/models/expression/quadratic_sum.rb +3 -1
  103. data/spec/support/models/expression/spatial.rb +2 -1
  104. data/spec/support/models/function/my_function.rb +3 -1
  105. data/spec/support/models/function/parabole.rb +1 -1
  106. data/spec/support/models/function/quadratic_sum.rb +2 -0
  107. data/spec/support/models/function/spatial.rb +2 -0
  108. data/spec/support/models/operator/inverse.rb +3 -1
  109. data/spec/support/models/operator/my_operator.rb +3 -1
  110. data/spec/support/models/variables_holder/dummy.rb +3 -1
  111. data/spec/support/shared_contexts/common.rb +4 -2
  112. data/spec/support/shared_examples/base_operations.rb +7 -4
  113. data/spec/support/shared_examples/common.rb +3 -1
  114. data/spec/support/shared_examples/operator/chained.rb +12 -6
  115. data/spec/support/shared_examples/operator/dual_term.rb +9 -8
  116. data/spec/support/shared_examples/operator/single_input.rb +7 -2
  117. data/spec/support/shared_examples/variable.rb +8 -4
  118. metadata +109 -30
  119. data/spec/integration/addition_spec.rb +0 -28
  120. data/spec/integration/formatted_spec.rb +0 -75
  121. data/spec/integration/readme/formatting_spec.rb +0 -34
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Equation::Builder
3
5
  attr_reader :variables
@@ -1,4 +1,6 @@
1
- class Danica::Exception < ::Exception
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
-
@@ -1,24 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
- module Expressable extend ::ActiveSupport::Concern
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
- self.delegate :to, :to_f, to: block_name
10
+ delegate :to, :to_f, to: block_name
8
11
 
9
- self.define_singleton_method(:build) do |*vars, &block|
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("define_method :#{block_name} do
16
- @#{block_name} ||= instance_eval(&block) if block
17
- end")
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
- self.define_singleton_method(:create) do |*vars, &block|
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
- self.public_send("#{key}=", value)
39
+ public_send("#{key}=", value)
34
40
  end
35
41
  end
36
42
  end
@@ -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) ** 2) /
13
+ ((x - average)**2) /
13
14
  (num(2) * variance)
14
- )
15
+ )
15
16
  end
16
17
 
17
18
  def variance
18
- @variance ||= variance_root ** 2
19
+ @variance ||= variance_root**2
19
20
  end
20
21
  end
21
22
  end
22
-
@@ -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
- return other.content == content &&
16
- other.format == format
17
+ other.content == content &&
18
+ other.format == format
17
19
  end
18
20
 
19
21
  def format
@@ -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
- autoload :Name, 'danica/function/name'
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
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Function::Name
3
5
  include Common
@@ -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(a, b)
10
- a + b
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
-
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Operator::Cos < Operator::Functional.build(operator: :cos)
3
5
  end
4
6
  end
5
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Operator::Division < Operator
3
5
  variables :numerator, :denominator
@@ -17,4 +19,3 @@ module Danica
17
19
  end
18
20
  end
19
21
  end
20
-
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Operator::Exponential < Operator::Functional.build(operator: :exp, tex: 'e^{:value:}')
3
5
  end
4
6
  end
5
-
@@ -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(%Q(
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(a, b)
11
- a * b
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 ** exponent.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
- "#{ wrap_as_group(base).to_gnu(options)}**(#{exponent.to_gnu(options)})"
17
+ "#{wrap_as_group(base).to_gnu(options)}**(#{exponent.to_gnu(options)})"
16
18
  end
17
19
  end
18
20
  end
19
-
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Operator::Sin < Operator::Functional.build(operator: :sin)
3
5
  end
4
6
  end
5
-
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Operator::SquaredRoot < Operator::Functional.build(operator: :sqrt, tex: '\sqrt{:value:}')
3
5
  end
4
6
  end
5
-
@@ -1,18 +1,21 @@
1
- module Danica
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?, true
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([ destiny ], clazz).build
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
  module VariablesHolder
3
5
  class Calculator
@@ -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( (container.content.name || key).to_sym => container )
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
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica::VariablesHolder
2
4
  class VariablesBuilder
3
5
  include Danica::DSL
@@ -41,4 +43,3 @@ module Danica::VariablesHolder
41
43
  end
42
44
  end
43
45
  end
44
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
- VERSION = '2.7.4'
4
+ VERSION = '2.7.5'
3
5
  end
@@ -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(gnuplot latex value)
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