Class: Darwinning::Gene

Inherits:
Object
  • Object
show all
Defined in:
lib/darwinning/gene.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Gene

Returns a new instance of Gene.


5
6
7
8
9
10
# File 'lib/darwinning/gene.rb', line 5

def initialize(options = {})
  @name = options.fetch(:name, '')
  @value_range = Array(options.fetch(:value_range, []))
  @invalid_values = Array(options.fetch(:invalid_values, []))
  @units = options.fetch(:units, '')
end

Instance Attribute Details

#invalid_valuesObject (readonly)

Returns the value of attribute invalid_values


3
4
5
# File 'lib/darwinning/gene.rb', line 3

def invalid_values
  @invalid_values
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/darwinning/gene.rb', line 3

def name
  @name
end

#unitsObject (readonly)

Returns the value of attribute units


3
4
5
# File 'lib/darwinning/gene.rb', line 3

def units
  @units
end

#valueObject (readonly)

Returns the value of attribute value


3
4
5
# File 'lib/darwinning/gene.rb', line 3

def value
  @value
end

#value_rangeObject (readonly)

Returns the value of attribute value_range


3
4
5
# File 'lib/darwinning/gene.rb', line 3

def value_range
  @value_range
end

Instance Method Details

#==(o) ⇒ Object


12
13
14
15
16
17
18
# File 'lib/darwinning/gene.rb', line 12

def ==(o)
  o.class == self.class &&
  o.name == name &&
  o.value_range == value_range &&
  o.invalid_values == invalid_values &&
  o.units == units
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/darwinning/gene.rb', line 20

def eql?(o)
  o == self
end

#expressObject


28
29
30
# File 'lib/darwinning/gene.rb', line 28

def express
  (value_range - invalid_values).sample
end

#hashObject


24
25
26
# File 'lib/darwinning/gene.rb', line 24

def hash
  name.hash ^ value_range.hash ^ invalid_values.hash ^ units.hash ^ value.hash
end

#is_valid_value?(value) ⇒ Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/darwinning/gene.rb', line 32

def is_valid_value?(value)
  value_range.include?(value) && !invalid_values.include?(value)
end