danica 2.1.0 → 2.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 429321643b0113576822386a859ccac11543b36f
4
- data.tar.gz: 2f34a7c65a4f47429b09a088cf5194a54fe139c1
3
+ metadata.gz: c83cfc75834923aafa5160c20aaa1f45b125274d
4
+ data.tar.gz: 9a7933dd0986b110dee4ee7156452a3ba4027f21
5
5
  SHA512:
6
- metadata.gz: 25f35ba1b18ef3ba0df7fcc2d9341524e4b79fbd40e55695bca92e9484ec2bd47eced63740ee3673b1d5364f0feeeb0af8065809de22cad5d1ee4c4ae5fc688a
7
- data.tar.gz: 24c2034b52eaaeb1905b9b5b8ab9d938d014eece4d51130404d24bf883a286bfd85f304a2780a4ddf73109e4b07b55c62b62087da50f11a9b19431853ad81de2
6
+ metadata.gz: 48ccbce0f6aa35e90078d8a9006f8f9e2e33119e26abd91cacfdd2496f068f4e4c09bf34a7c89aa109d13807812a2157fd3f4a48bbc2681898445e559d02a37e
7
+ data.tar.gz: c505f5b99d34053f28b1c5e5c2d1406814acf2f6935d2eb3e9b6f7fd9d7168a9010282fadf0c514f086463206d3bd262298c4551a6c935ebdcad1f7167f15f30
@@ -8,6 +8,19 @@ module Danica
8
8
 
9
9
  default_value :priority, 3
10
10
  default_value :is_grouped?, false
11
+ delegate :to_f, :to_tex, :to_gnu, to: :function
12
+
13
+ def self.build(*vars, &block)
14
+ Class.new(self) do
15
+ variables(*vars)
16
+
17
+ private
18
+
19
+ define_method :function do
20
+ @function ||= instance_eval(&block)
21
+ end
22
+ end
23
+ end
11
24
 
12
25
  def initialize(*args)
13
26
  options = args.extract_options!
@@ -1,3 +1,3 @@
1
1
  module Danica
2
- VERSION = '2.1.0'
2
+ VERSION = '2.1.1'
3
3
  end
@@ -1,6 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Danica::Function do
4
+ describe '.build' do
5
+ let(:variables) { %i(x y) }
6
+ let(:function_class) do
7
+ described_class.build(*variables) do
8
+ Danica::Power.new(x, y)
9
+ end
10
+ end
11
+ let(:function) do
12
+ function_class.new
13
+ end
14
+
15
+ it 'returns a function class' do
16
+ expect(function_class.superclass).to eq(described_class)
17
+ end
18
+
19
+ it 'returns a class whose instance responds to the variables' do
20
+ variables.each do |variable|
21
+ expect(function).to respond_to(variable)
22
+ end
23
+ end
24
+
25
+ it 'returns a function that uses the block to process to_tex' do
26
+ expect(function.to_tex).to eq('x^{y}')
27
+ end
28
+
29
+ it 'returns a function that uses the block to process to_gnu' do
30
+ expect(function.to_gnu).to eq('x**(y)')
31
+ end
32
+
33
+ it 'returns a function thtat knows how to calculate' do
34
+ expect(function.calculate(x: 2, y: 3)).to eq(8)
35
+ end
36
+ end
37
+
4
38
  describe 'spatial' do
5
39
  let(:variables) do
6
40
  {
@@ -1,12 +1,11 @@
1
1
  module Danica
2
2
  class Function::Baskara < Function
3
3
  variables :a, :b, :c
4
- delegate :to_f, :to_tex, :to_gnu, to: :division
5
4
 
6
5
  private
7
6
 
8
- def division
9
- numerator / denominator
7
+ def function
8
+ @function ||= numerator / denominator
10
9
  end
11
10
 
12
11
  def numerator
@@ -1,12 +1,11 @@
1
1
  module Danica
2
2
  class Function::Gauss < Function
3
3
  variables :x, median: :u, variance_root: { latex: '\theta', gnu: :v }
4
- delegate :to_f, :to_tex, :to_gnu, to: :product
5
4
 
6
5
  private
7
6
 
8
- def product
9
- @sum ||= Product.new(parcels)
7
+ def function
8
+ @function ||= Product.new(parcels)
10
9
  end
11
10
 
12
11
  def parcels
@@ -1,12 +1,11 @@
1
1
  module Danica
2
2
  class Function::Spatial < Function
3
3
  variables :time, :acceleration, :initial_space, :initial_velocity
4
- delegate :to_f, :to_tex, :to_gnu, to: :sum
5
4
 
6
5
  private
7
6
 
8
- def sum
9
- @sum ||= Sum.new(parcels)
7
+ def function
8
+ @function ||= Sum.new(parcels)
10
9
  end
11
10
 
12
11
  def parcels
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danica
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee