Class: IDFTags::BadWordLexicon
- Inherits:
-
Object
- Object
- IDFTags::BadWordLexicon
- Defined in:
- lib/IDFTags/bad_word_lexicon.rb
Instance Attribute Summary collapse
-
#bad_words ⇒ Object
readonly
Returns the value of attribute bad_words.
-
#locale ⇒ Object
Returns the value of attribute locale.
Class Method Summary collapse
Instance Method Summary collapse
- #add(bad_word) ⇒ Object
- #add_all(bad_words) ⇒ Object
-
#initialize(locale, bad_words = []) ⇒ BadWordLexicon
constructor
A new instance of BadWordLexicon.
- #traverse(hash, &blk) ⇒ Object
Constructor Details
#initialize(locale, bad_words = []) ⇒ BadWordLexicon
Returns a new instance of BadWordLexicon.
9 10 11 12 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 9 def initialize locale, bad_words = [] @locale = locale @bad_words = bad_words end |
Instance Attribute Details
#bad_words ⇒ Object (readonly)
Returns the value of attribute bad_words.
7 8 9 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 7 def bad_words @bad_words end |
#locale ⇒ Object
Returns the value of attribute locale.
6 7 8 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 6 def locale @locale end |
Class Method Details
.from_yml(filename) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 24 def self.from_yml filename if File.exist? filename content = YAML.load_file(filename) result = BadWordLexicon.new content.keys.first.to_sym result.traverse(content) { |node| result.add node } result end end |
Instance Method Details
#add(bad_word) ⇒ Object
14 15 16 17 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 14 def add bad_word @bad_words << bad_word if bad_word @bad_words.uniq! end |
#add_all(bad_words) ⇒ Object
19 20 21 22 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 19 def add_all bad_words @bad_words += bad_words if bad_words @bad_words.uniq! end |
#traverse(hash, &blk) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/IDFTags/bad_word_lexicon.rb', line 37 def traverse hash, &blk case hash when Hash hash.each { |_, v| traverse(v, &blk) } when Array hash.each { |v| traverse(v, &blk) } else blk.call(hash) end end |