improve constant and empty to_s
This commit is contained in:
parent
dda5bc35ed
commit
04965ac35a
9 changed files with 25 additions and 6 deletions
|
@ -7,7 +7,16 @@ class Logic::Constant < Logic::Term
|
||||||
|
|
||||||
def compute(_champs = nil) = @value
|
def compute(_champs = nil) = @value
|
||||||
|
|
||||||
def to_s = @value.to_s
|
def to_s
|
||||||
|
case @value
|
||||||
|
when TrueClass
|
||||||
|
I18n.t('utils.yes')
|
||||||
|
when FalseClass
|
||||||
|
I18n.t('utils.no')
|
||||||
|
else
|
||||||
|
@value.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
case @value
|
case @value
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Logic::Empty < Logic::Term
|
class Logic::Empty < Logic::Term
|
||||||
def to_s = "empty member"
|
def to_s = I18n.t('logic.empty')
|
||||||
|
|
||||||
def type = :empty
|
def type = :empty
|
||||||
|
|
||||||
|
|
3
config/locales/models/logic/en.yml
Normal file
3
config/locales/models/logic/en.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
en:
|
||||||
|
logic:
|
||||||
|
empty: empty member
|
3
config/locales/models/logic/fr.yml
Normal file
3
config/locales/models/logic/fr.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fr:
|
||||||
|
logic:
|
||||||
|
empty: un membre vide
|
|
@ -8,7 +8,7 @@ describe Logic::And do
|
||||||
|
|
||||||
describe '#to_s' do
|
describe '#to_s' do
|
||||||
it do
|
it do
|
||||||
expect(and_from([true, false, true]).to_s).to eq "(true && false && true)"
|
expect(and_from([true, false, true]).to_s).to eq "(Oui && Non && Oui)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe Logic::BinaryOperator do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#errors' do
|
describe '#errors' do
|
||||||
it { expect(greater_than(constant(1), constant(true)).errors).to eq(['les types sont incompatibles : (1 > true)']) }
|
it { expect(greater_than(constant(1), constant(true)).errors).to eq(['les types sont incompatibles : (1 > Oui)']) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,8 @@ describe Logic::Constant do
|
||||||
it { expect(empty).to eq(empty) }
|
it { expect(empty).to eq(empty) }
|
||||||
it { expect(empty).not_to eq(constant(true)) }
|
it { expect(empty).not_to eq(constant(true)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#to_s' do
|
||||||
|
it { expect(empty.to_s).to eq('un membre vide') }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe Logic::Eq do
|
||||||
|
|
||||||
describe '#errors' do
|
describe '#errors' do
|
||||||
it { expect(ds_eq(constant(true), constant(true)).errors).to be_empty }
|
it { expect(ds_eq(constant(true), constant(true)).errors).to be_empty }
|
||||||
it { expect(ds_eq(constant(true), constant(1)).errors).to eq(["les types sont incompatibles : (true == 1)"]) }
|
it { expect(ds_eq(constant(true), constant(1)).errors).to eq(["les types sont incompatibles : (Oui == 1)"]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#==' do
|
describe '#==' do
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe Logic::Or do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#to_s' do
|
describe '#to_s' do
|
||||||
it { expect(or_from([true, false, true]).to_s).to eq "(true || false || true)" }
|
it { expect(or_from([true, false, true]).to_s).to eq "(Oui || Non || Oui)" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def or_from(boolean_to_constants)
|
def or_from(boolean_to_constants)
|
Loading…
Add table
Add a link
Reference in a new issue