danica 2.7.2 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 204973e375504667567ab1246d44e05a1375e407
4
- data.tar.gz: 0ec10d6273e79affbbb3624795cc00dd06321687
3
+ metadata.gz: 1cb8a797fc699f5234e08cd31d87caa9706cea6a
4
+ data.tar.gz: 03cc19287859762cf1554f7243f550905bede4c3
5
5
  SHA512:
6
- metadata.gz: d63fd9fa21b3a5894d55d3a53d6af203f4bfb2f4f78162a9c7d38877f146c9a69f04851fffa6a331f03d2bd533f0945a3de70b88236e577af278e95fdc3cccae
7
- data.tar.gz: 21d8fb184a94220c656d8631cf9b230f6f4911cc675333b5188176b379177499cb2522c4e2a306107d4347aa86585ec2c9ee281cedab70e47eaff743668b567f
6
+ metadata.gz: 32c7797d3108c0598c6c18ed33e355e669c03fa944639038ab0d7fb3c2afc7c74feb9975c06e4c2fd80d253e9a2ad1c80d3d44263996c760836a204fe5b798ae
7
+ data.tar.gz: 16078df081cd008fa485d03f48a006030021cdd7a22ccccad7b86a6f3b4f9d55142429405fb88fc3d88fdadaee3982a3797f93bb7130ebee4ad15ee3e3c14999
@@ -47,11 +47,11 @@ module Danica
47
47
  end
48
48
 
49
49
  def tex(**options)
50
- formatted(:tex, options)
50
+ formatted(format: :tex, **options)
51
51
  end
52
52
 
53
53
  def gnu(**options)
54
- formatted(:gnu, options)
54
+ formatted(format: :gnu, **options)
55
55
  end
56
56
 
57
57
  def formatted(*args)
@@ -1,14 +1,13 @@
1
1
  class Danica::Formatted
2
- attr_reader :content, :format, :decimals
2
+ attr_reader :content, :options
3
3
 
4
- def initialize(content, format, decimals: nil)
4
+ def initialize(content, **options)
5
5
  @content = content
6
- @format = format
7
- @decimals = decimals
6
+ @options = options
8
7
  end
9
8
 
10
9
  def to_s
11
- content.to(format, decimals: decimals)
10
+ content.to(format, options)
12
11
  end
13
12
 
14
13
  def ==(other)
@@ -17,13 +16,29 @@ class Danica::Formatted
17
16
  other.format == format
18
17
  end
19
18
 
19
+ def format
20
+ options[:format]
21
+ end
22
+
20
23
  def repack(object)
21
24
  self.class.new(
22
25
  object,
23
- format
26
+ options
24
27
  )
25
28
  end
26
29
 
30
+ def to_tex(**opts)
31
+ to(:tex, **opts)
32
+ end
33
+
34
+ def to_gnu(**opts)
35
+ to(:gnu, **opts)
36
+ end
37
+
38
+ def to(format, **opts)
39
+ content.to(format, options.merge(opts))
40
+ end
41
+
27
42
  private
28
43
 
29
44
  def method_missing(method, *args)
@@ -1,3 +1,3 @@
1
1
  module Danica
2
- VERSION = '2.7.2'
2
+ VERSION = '2.7.3'
3
3
  end
@@ -81,6 +81,21 @@ describe Danica::Common do
81
81
  expect(subject.to_tex).to eq('formatted: tex')
82
82
  end
83
83
  end
84
+
85
+ context 'when formatted was generated with gnu and with options' do
86
+ let(:number) { Danica::Wrapper::Number.new(1.0/3) }
87
+ subject { number.gnu(decimals: 3) }
88
+
89
+ it 'formats with the current options' do
90
+ expect(subject.to_tex).to eq('0.333')
91
+ end
92
+
93
+ context 'but overwritting options' do
94
+ it 'formats with the current options' do
95
+ expect(subject.to_tex(decimals: 4)).to eq('0.3333')
96
+ end
97
+ end
98
+ end
84
99
  end
85
100
 
86
101
  describe '#to_gnu' do
@@ -90,6 +105,38 @@ describe Danica::Common do
90
105
  expect(subject.to_gnu).to eq('formatted: gnu')
91
106
  end
92
107
  end
108
+
109
+ context 'when formatted was generated with tex and with options' do
110
+ let(:number) { Danica::Wrapper::Number.new(1.0/3) }
111
+ subject { number.tex(decimals: 3) }
112
+
113
+ it 'formats with the current options' do
114
+ expect(subject.to_gnu).to eq('0.333')
115
+ end
116
+
117
+ context 'but overwritting options' do
118
+ it 'formats with the current options' do
119
+ expect(subject.to_gnu(decimals: 4)).to eq('0.3333')
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ describe 'to' do
126
+ context 'when already formatted with options' do
127
+ let(:number) { Danica::Wrapper::Number.new(1.0/3) }
128
+ subject { number.tex(decimals: 3) }
129
+
130
+ it 'uses to with options' do
131
+ expect(subject.to(:gnu)).to eq('0.333')
132
+ end
133
+
134
+ context 'when calling with options' do
135
+ it 'uses options' do
136
+ expect(subject.to(:gnu, decimals: 4)).to eq('0.3333')
137
+ end
138
+ end
139
+ end
93
140
  end
94
141
 
95
142
  describe '#tex' do
@@ -98,12 +145,12 @@ describe Danica::Common do
98
145
  end
99
146
 
100
147
  it 'knows how to return a tex string' do
101
- expect(subject.tex.to_s).to eq('tex {:decimals=>nil}')
148
+ expect(subject.tex.to_s).to eq('tex {:format=>:tex}')
102
149
  end
103
150
 
104
151
  context 'when passing options' do
105
152
  it 'uses the arguments' do
106
- expect(subject.tex(decimals: 3).to_s).to eq('tex {:decimals=>3}')
153
+ expect(subject.tex(decimals: 3).to_s).to eq('tex {:format=>:tex, :decimals=>3}')
107
154
  end
108
155
  end
109
156
  end
@@ -114,23 +161,23 @@ describe Danica::Common do
114
161
  end
115
162
 
116
163
  it 'knows how to return a gnu string' do
117
- expect(subject.gnu.to_s).to eq('gnu {:decimals=>nil}')
164
+ expect(subject.gnu.to_s).to eq('gnu {:format=>:gnu}')
118
165
  end
119
166
 
120
167
  context 'when passing options' do
121
168
  it 'uses the arguments' do
122
- expect(subject.gnu(decimals: 3).to_s).to eq('gnu {:decimals=>3}')
169
+ expect(subject.gnu(decimals: 3).to_s).to eq('gnu {:format=>:gnu, :decimals=>3}')
123
170
  end
124
171
  end
125
172
  end
126
173
 
127
174
  describe '#formatted' do
128
175
  it do
129
- expect(subject.formatted(:gnu)).to be_a(Danica::Formatted)
176
+ expect(subject.formatted(format: :gnu)).to be_a(Danica::Formatted)
130
177
  end
131
178
 
132
179
  it 'knows how to return to build the string string' do
133
- expect(subject.formatted(:gnu, decimals: 3).to_s).to eq('gnu {:decimals=>3}')
180
+ expect(subject.formatted(format: :gnu, decimals: 3).to_s).to eq('gnu {:format=>:gnu, :decimals=>3}')
134
181
  end
135
182
  end
136
183
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  shared_examples 'a formatted result' do |output|
5
4
  it do
6
5
  expect(result).to be_a(described_class)
@@ -29,7 +28,23 @@ describe Danica::Formatted do
29
28
  let(:format) { :tex }
30
29
  let(:options) { {} }
31
30
  subject do
32
- described_class.new(content, format, options)
31
+ described_class.new(content, format: format, **options)
32
+ end
33
+
34
+ describe '#repack' do
35
+ let(:expression) { Danica::Wrapper::Number.new(1.0 / 3) }
36
+
37
+ it do
38
+ expect(subject.repack(expression)).to be_a(Danica::Formatted)
39
+ end
40
+
41
+ context 'when there are options' do
42
+ let(:options) { { decimals: 3 } }
43
+
44
+ it 'wraps expression with options' do
45
+ expect(subject.repack(expression).to_s).to eq('0.333')
46
+ end
47
+ end
33
48
  end
34
49
 
35
50
  describe '#to_s' do
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.7.2
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport