Class: Reflekt::FloatRule

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

Instance Attribute Summary

Attributes inherited from Rule

#type

Instance Method Summary collapse

Constructor Details

#initializeFloatRule

Returns a new instance of FloatRule.



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

def initialize()

  @type = :float
  @min = nil
  @max = nil

end

Instance Method Details

#randomObject



54
55
56
# File 'lib/rules/float_rule.rb', line 54

def random()
  rand(@min..@max)
end

#resultObject



46
47
48
49
50
51
52
# File 'lib/rules/float_rule.rb', line 46

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

#test(value) ⇒ Object

Parameters:

  • value (Float)


38
39
40
41
42
43
44
# File 'lib/rules/float_rule.rb', line 38

def test(value)

  return false if value < @min
  return false if value > @max

  true
end

#train(meta) ⇒ Object

Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rules/float_rule.rb', line 17

def train(meta)

  value = meta[:value]

  if @min.nil?
    @min = value
  else
    @min = value if value < @min
  end

  if @max.nil?
    @max = value
  else
    @max = value if value > @max
  end

end