Class: Dict::Dictionary
- Inherits:
-
Object
- Object
- Dict::Dictionary
- Defined in:
- lib/dict/dictionary.rb
Overview
It is a base class for classes fetching results from Web dictionaries.
Direct Known Subclasses
Defined Under Namespace
Classes: ConnectError
Class Method Summary collapse
Instance Method Summary collapse
-
#check_arguments(word) ⇒ Object
Checks if word was given correctly.
-
#initialize(word) ⇒ Dictionary
constructor
A new instance of Dictionary.
-
#uri(url, word = nil) ⇒ Object
Returns an instance of URI::HTTP class.
Constructor Details
#initialize(word) ⇒ Dictionary
Returns a new instance of Dictionary.
10 11 12 13 14 |
# File 'lib/dict/dictionary.rb', line 10 def initialize(word) check_arguments(word) @word = downcase_word(word) @result = Dict::Result.new(@word) end |
Class Method Details
.message ⇒ Object
26 27 28 |
# File 'lib/dict/dictionary.rb', line 26 def self. 'There\'s no such dictionary in database.' end |
Instance Method Details
#check_arguments(word) ⇒ Object
Checks if word was given correctly.
22 23 24 |
# File 'lib/dict/dictionary.rb', line 22 def check_arguments(word) raise ArgumentError.new("No given word") if word.empty? end |
#uri(url, word = nil) ⇒ Object
Returns an instance of URI::HTTP class.
17 18 19 |
# File 'lib/dict/dictionary.rb', line 17 def uri(url, word = nil) word == nil ? URI(URI.escape(url)) : URI(URI.escape(url + word.downcase.tr(' ', '_'))) end |