Class: Senko::Vocabulary

Inherits:
Object
  • Object
show all
Defined in:
lib/senko/vocabulary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_keywords = {}) ⇒ Vocabulary

Returns a new instance of Vocabulary.



7
8
9
# File 'lib/senko/vocabulary.rb', line 7

def initialize(custom_keywords = {})
  @custom_keywords = custom_keywords || {}
end

Instance Attribute Details

#custom_keywordsObject (readonly)

Returns the value of attribute custom_keywords.



5
6
7
# File 'lib/senko/vocabulary.rb', line 5

def custom_keywords
  @custom_keywords
end

Instance Method Details

#custom?(keyword) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/senko/vocabulary.rb', line 11

def custom?(keyword)
  @custom_keywords.key?(keyword)
end

#register(keyword, validator) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
# File 'lib/senko/vocabulary.rb', line 19

def register(keyword, validator)
  raise ArgumentError, 'keyword validator must respond to call' unless validator.respond_to?(:call)

  @custom_keywords[keyword.to_s] = validator
end

#validator_for(keyword) ⇒ Object



15
16
17
# File 'lib/senko/vocabulary.rb', line 15

def validator_for(keyword)
  @custom_keywords[keyword]
end