Class: BooleanRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/rules/boolean_rule.rb

Instance Attribute Summary

Attributes inherited from Rule

#type

Instance Method Summary collapse

Constructor Details

#initializeBooleanRule

Returns a new instance of BooleanRule.



6
7
8
9
10
11
# File 'lib/rules/boolean_rule.rb', line 6

def initialize()

  @type = :bool
  @booleans = Set.new()

end

Instance Method Details

#randomObject



43
44
45
# File 'lib/rules/boolean_rule.rb', line 43

def random()
  @booleans.to_a.sample
end

#resultObject



36
37
38
39
40
41
# File 'lib/rules/boolean_rule.rb', line 36

def result()
  {
    :type => @type,
    :booleans => @booleans
  }
end

#test(value) ⇒ Object

Parameters:

  • value (Boolean)


29
30
31
32
33
34
# File 'lib/rules/boolean_rule.rb', line 29

def test(value)

  # Booleans are stored as strings.
  @booleans.include? value.to_s

end

#train(meta) ⇒ Object

Parameters:



16
17
18
19
20
21
22
23
24
# File 'lib/rules/boolean_rule.rb', line 16

def train(meta)

  value = meta[:value]

  unless value.nil?
    @booleans << value
  end

end