Class: HintableLevenshtein::RuleSet

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/hintable_levenshtein/rule_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score, *rules) ⇒ RuleSet

Returns a new instance of RuleSet.



7
8
9
10
# File 'lib/hintable_levenshtein/rule_set.rb', line 7

def initialize(score, *rules)
  @rules = rules
  @score = score
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



6
7
8
# File 'lib/hintable_levenshtein/rule_set.rb', line 6

def rules
  @rules
end

#scoreObject (readonly)

Returns the value of attribute score.



6
7
8
# File 'lib/hintable_levenshtein/rule_set.rb', line 6

def score
  @score
end

Instance Method Details

#match?(events) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/hintable_levenshtein/rule_set.rb', line 16

def match?(events)
  return if events.size != rules.size
  events.each_with_index do |e, idx|
    return unless rules[idx].match?(e)
  end
  true
end

#to_sObject



12
13
14
# File 'lib/hintable_levenshtein/rule_set.rb', line 12

def to_s
  "#{score} -> #{rules.collect{|r| r.to_s} * ', '}"
end