to_s
This commit is contained in:
parent
f98d1463a6
commit
43f926a1de
11 changed files with 14 additions and 14 deletions
|
@ -7,5 +7,5 @@ class Logic::And < Logic::NAryOperator
|
|||
@operands.map { |operand| operand.compute(champs) }.all?
|
||||
end
|
||||
|
||||
def to_s = "(#{@operands.map(&:to_s).join(' && ')})"
|
||||
def to_s(type_de_champs) = "(#{@operands.map { |o| o.to_s(type_de_champs) }.join(' && ')})"
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ class Logic::BinaryOperator < Logic::Term
|
|||
l&.send(operation, r) || false
|
||||
end
|
||||
|
||||
def to_s = "(#{@left} #{operation} #{@right})"
|
||||
def to_s(type_de_champs) = "(#{@left.to_s(type_de_champs)} #{operation} #{@right.to_s(type_de_champs)})"
|
||||
|
||||
def ==(other)
|
||||
self.class == other.class &&
|
||||
|
|
|
@ -42,7 +42,7 @@ class Logic::ChampValue < Logic::Term
|
|||
end
|
||||
end
|
||||
|
||||
def to_s = type_de_champ&.libelle # TODO: gerer le cas ou un tdc est supprimé
|
||||
def to_s(type_de_champs) = type_de_champ(type_de_champs)&.libelle # TODO: gerer le cas ou un tdc est supprimé
|
||||
|
||||
def type(type_de_champs)
|
||||
case type_de_champ(type_de_champs)&.type_champ # TODO: gerer le cas ou un tdc est supprimé
|
||||
|
|
|
@ -7,7 +7,7 @@ class Logic::Constant < Logic::Term
|
|||
|
||||
def compute(_champs = nil) = @value
|
||||
|
||||
def to_s
|
||||
def to_s(_type_de_champs = [])
|
||||
case @value
|
||||
when TrueClass
|
||||
I18n.t('utils.yes')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Logic::Empty < Logic::Term
|
||||
def to_s = I18n.t('logic.empty')
|
||||
def to_s(_type_de_champs = []) = I18n.t('logic.empty')
|
||||
|
||||
def type(_type_de_champs = []) = :empty
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Logic::EmptyOperator < Logic::BinaryOperator
|
||||
def to_s = "empty operator"
|
||||
def to_s(_type_de_champs = []) = "empty operator"
|
||||
|
||||
def type(_type_de_champs = []) = :empty
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class Logic::NAryOperator < Logic::Term
|
|||
|
||||
not_booleans = @operands.filter { |operand| operand.type(type_de_champs) != :boolean }
|
||||
if not_booleans.present?
|
||||
errors += ["'#{operator_name}' ne contient pas que des booléens : #{not_booleans.map(&:to_s).join(', ')}"]
|
||||
errors += ["'#{operator_name}' ne contient pas que des booléens : #{not_booleans.map { |o| o.to_s(type_de_champs) }.join(', ')}"]
|
||||
end
|
||||
|
||||
errors + @operands.flat_map { |operand| operand.errors(type_de_champs) }
|
||||
|
|
|
@ -7,5 +7,5 @@ class Logic::Or < Logic::NAryOperator
|
|||
@operands.map { |operand| operand.compute(champs) }.any?
|
||||
end
|
||||
|
||||
def to_s = "(#{@operands.map(&:to_s).join(' || ')})"
|
||||
def to_s(type_de_champs = []) = "(#{@operands.map { |o| o.to_s(type_de_champs) }.join(' || ')})"
|
||||
end
|
||||
|
|
|
@ -317,7 +317,7 @@ class ProcedureRevision < ApplicationRecord
|
|||
changed = kept
|
||||
.map { |sid| [sid, from_h[sid], to_h[sid]] }
|
||||
.flat_map do |sid, from, to|
|
||||
compare_type_de_champ(from.type_de_champ, to.type_de_champ)
|
||||
compare_type_de_champ(from.type_de_champ, to.type_de_champ, from_coordinates, to_coordinates)
|
||||
.each { |h| h[:_position] = to_sids.index(sid) }
|
||||
end
|
||||
|
||||
|
@ -327,7 +327,7 @@ class ProcedureRevision < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def compare_type_de_champ(from_type_de_champ, to_type_de_champ)
|
||||
def compare_type_de_champ(from_type_de_champ, to_type_de_champ, from_coordinates, to_coordinates)
|
||||
changes = []
|
||||
if from_type_de_champ.type_champ != to_type_de_champ.type_champ
|
||||
changes << {
|
||||
|
@ -385,8 +385,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
attribute: :condition,
|
||||
label: from_type_de_champ.libelle,
|
||||
private: from_type_de_champ.private?,
|
||||
from: from_type_de_champ.condition&.to_s,
|
||||
to: to_type_de_champ.condition&.to_s,
|
||||
from: from_type_de_champ.condition&.to_s(from_coordinates.map(&:type_de_champ)),
|
||||
to: to_type_de_champ.condition&.to_s(to_coordinates.map(&:type_de_champ)),
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ describe Logic::And do
|
|||
|
||||
describe '#to_s' do
|
||||
it do
|
||||
expect(and_from([true, false, true]).to_s).to eq "(Oui && Non && Oui)"
|
||||
expect(and_from([true, false, true]).to_s([])).to eq "(Oui && Non && Oui)"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ describe Logic::BinaryOperator do
|
|||
end
|
||||
|
||||
describe '#to_s' do
|
||||
it { expect(two_greater_than_one.to_s).to eq('(2 > 1)') }
|
||||
it { expect(two_greater_than_one.to_s([])).to eq('(2 > 1)') }
|
||||
end
|
||||
|
||||
describe '#==' do
|
||||
|
|
Loading…
Reference in a new issue