class Scoruby::Predicates::CompoundPredicate

Attributes

field[R]

Public Class Methods

new(pred_xml) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 8
def initialize(pred_xml)
  attributes = pred_xml.attributes
  children   = pred_xml.children

  @boolean_operator = attributes['booleanOperator'].value
  @predicates       = []
  @predicates << PredicateFactory.for(children[0])
  @predicates << PredicateFactory.for(children[1])
  @field = @predicates.map(&:field).flatten.compact
end

Public Instance Methods

missing?(features) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 25
def missing?(features)
  @field.any? { |f| !features.keys.include?(f) }
end
true?(features) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 19
def true?(features)
  return surrogate?(features) if @boolean_operator == 'surrogate'
  return or?(features) if @boolean_operator == 'or'
  and?(features) if @boolean_operator == 'and'
end

Private Instance Methods

and?(features) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 44
def and?(features)
  @predicates.all? { |p| p.true?(features) }
end
first_missing?(features) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 36
def first_missing?(features)
  @predicates[0].missing?(features)
end
or?(features) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 40
def or?(features)
  @predicates.any? { |p| p.true?(features) }
end
surrogate?(features) click to toggle source
# File lib/scoruby/predicates/compound_predicate.rb, line 31
def surrogate?(features)
  return @predicates[1].true?(features) if first_missing?(features)
  @predicates[0].true?(features)
end