Class: Daedal::Attributes::ScoreFunctionArray

Inherits:
Array
  • Object
show all
Defined in:
lib/daedal/attributes/score_function_array.rb

Instance Method Summary collapse

Instance Method Details

#<<(function) ⇒ Object

Raises:

  • (Virtus::CoercionError)


5
6
7
8
9
# File 'lib/daedal/attributes/score_function_array.rb', line 5

def <<(function)
  raise Virtus::CoercionError.new(value, 'Daedal::Attributes::ScoreFunction') unless valid_score_function?(function)

  super function
end

#unshift(function) ⇒ Object

Raises:

  • (Virtus::CoercionError)


11
12
13
14
15
# File 'lib/daedal/attributes/score_function_array.rb', line 11

def unshift(function)
  raise Virtus::CoercionError.new(f, 'Daedal::Attributes::ScoreFunctions') unless valid_score_function?(function)

  super function
end

#valid_score_function?(score_function) ⇒ Boolean

Values should be an array of hashes with filter & weight

Returns:

  • (Boolean)


19
20
21
# File 'lib/daedal/attributes/score_function_array.rb', line 19

def valid_score_function?(score_function)
  score_function[:filter].respond_to?(:hash) && score_function[:weight].respond_to?(:hash)
end