Class: Reflekt::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.


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

def initialize()
  @type = :bool
  @booleans = Set.new()
end

Instance Method Details

#randomObject


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

def random()
  @booleans.to_a.sample
end

#resultObject


31
32
33
34
35
36
# File 'lib/rules/boolean_rule.rb', line 31

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

#test(value) ⇒ Object

Parameters:

  • value (Boolean)

26
27
28
29
# File 'lib/rules/boolean_rule.rb', line 26

def test(value)
  # Booleans are stored as strings.
  @booleans.include? value.to_s
end

#train(meta) ⇒ Object

Parameters:


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

def train(meta)
  value = meta[:value]

  unless value.nil?
    @booleans << value
  end
end