class TEF::ProgramSelection::ID
Program ID
class.
This class is meant to uniquely identify a specific program. It also provides a {#hash} and {#==} operator, allowing the use as hash key.
Attributes
groups[R]
@return [Array<String>] List of groups this program belongs to.
Further defines the program by providing a bit of context, such as 'portal', 'glad os', etc.
hash[R]
@return [Numeric] The hash key of this ID
. Allows
identification and comparison of keys in a Hash. Two keys match if they have the same groups, title and are of the same variant.
title[R]
@return [String] Main title of the program.
Often defines the action the program will execute, i.e. 'hello' or 'red alert'
variant[R]
@return [String] The variant of this program.
Its main purpose is to separate different variations of the same general program, such as when there are different 'hello's from the same groups. Has no effect on the actual selection.
Public Class Methods
new(title, groups, variant)
click to toggle source
# File lib/tef/ProgramSelection/ProgramID.rb, line 47 def initialize(title, groups, variant) @title = title; @groups = groups.sort @variant = variant @hash = @title.hash ^ @groups.hash ^ @variant.hash end
Public Instance Methods
<=>(other)
click to toggle source
@return [-1..1] Sorting operator, sorts alphabetically by title,
then group, then variant.
# File lib/tef/ProgramSelection/ProgramID.rb, line 72 def <=>(other) tsort = (@title <=> other.title) return tsort unless tsort.zero? gsort = (@groups <=> other.groups) return gsort unless gsort.zero? @variant <=> other.variant end
==(other)
click to toggle source
@return [true, false] Two keys match if
they have the same groups, title and are of the same variant.
# File lib/tef/ProgramSelection/ProgramID.rb, line 57 def ==(other) if other.is_a? String @title == other elsif other.is_a? ID return false if @title != other.title return false if @variant != other.variant return false if @groups != other.groups true end end
Also aliased as: eql?
get_scoring(group_weights)
click to toggle source
Compute the selection score for this ID
. Used in {Selector} to determine the best-matching program ID
for a given group scoring.
@param [Hash<String, Numeric>] Hash of group weights. Any group
of this ID that has a weight will be added to the score.
@return [Numeric] Sum of the selected group weights.
# File lib/tef/ProgramSelection/ProgramID.rb, line 89 def get_scoring(group_weights) score = 0; @groups.each do |g| if weight = group_weights[g] score += weight end end score end