Class: Rule
- Inherits:
-
Object
- Object
- Rule
- Defined in:
- lib/bad_word_detector/rule.rb
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(char, symbol, weight = nil) ⇒ Rule
constructor
A new instance of Rule.
- #merge(hash) ⇒ Object
Constructor Details
#initialize(char, symbol, weight = nil) ⇒ Rule
Returns a new instance of Rule.
7 8 9 10 11 12 |
# File 'lib/bad_word_detector/rule.rb', line 7 def initialize(char, symbol, weight = nil) @char = char @symbol = symbol @weight = weight || 2 @length = char.length end |
Instance Attribute Details
#char ⇒ Object (readonly)
Returns the value of attribute char.
2 3 4 |
# File 'lib/bad_word_detector/rule.rb', line 2 def char @char end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
2 3 4 |
# File 'lib/bad_word_detector/rule.rb', line 2 def length @length end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
2 3 4 |
# File 'lib/bad_word_detector/rule.rb', line 2 def symbol @symbol end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
2 3 4 |
# File 'lib/bad_word_detector/rule.rb', line 2 def weight @weight end |
Class Method Details
.empty(char) ⇒ Object
29 30 31 |
# File 'lib/bad_word_detector/rule.rb', line 29 def empty(char) self.new(char, '', 0.2) end |
.self(char) ⇒ Object
26 27 28 |
# File 'lib/bad_word_detector/rule.rb', line 26 def self(char) self.new(char, char, 3) end |
Instance Method Details
#merge(hash) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bad_word_detector/rule.rb', line 14 def merge(hash) new_hash = hash.hmap do |k, v| [k.to_s, v] end self.class.new( new_hash[:char] || self.char, new_hash[:symbol] || self.symbol, new_hash[:weight] || self.weight, ) end |