Class: Opencdd::InstanceRule

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/instance_rule.rb

Defined Under Namespace

Classes: Exception, Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass:, groups:, exceptions: []) ⇒ InstanceRule

Returns a new instance of InstanceRule.



10
11
12
13
14
15
# File 'lib/opencdd/instance_rule.rb', line 10

def initialize(klass:, groups:, exceptions: [])
  @klass = klass
  @groups = groups
  @exceptions = exceptions
  freeze
end

Instance Attribute Details

#exceptionsObject (readonly)

Returns the value of attribute exceptions.



8
9
10
# File 'lib/opencdd/instance_rule.rb', line 8

def exceptions
  @exceptions
end

#groupsObject (readonly)

Returns the value of attribute groups.



8
9
10
# File 'lib/opencdd/instance_rule.rb', line 8

def groups
  @groups
end

#klassObject (readonly)

Returns the value of attribute klass.



8
9
10
# File 'lib/opencdd/instance_rule.rb', line 8

def klass
  @klass
end

Instance Method Details

#expandObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/opencdd/instance_rule.rb', line 17

def expand
  return [] if @groups.empty?

  per_group = @groups.map { |g| expand_group(g) }
  return [] if per_group.any?(&:empty?)

  product = per_group.reduce do |acc, rows|
    acc.product(rows).map { |a, b| a.merge(b) }
  end

  product.reject { |row| exception_match?(row) }
          .map { |row| strip_internal(row) }
end