Class: Dict::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/dict/dictionary.rb

Overview

It is a base class for classes fetching results from Web dictionaries.

Direct Known Subclasses

Glosbe, Wiktionary

Defined Under Namespace

Classes: ConnectError

Class Method Summary collapse

Instance Method Summary collapse

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

.messageObject



26
27
28
# File 'lib/dict/dictionary.rb', line 26

def self.message
  'There\'s no such dictionary in database.'
end

Instance Method Details

#check_arguments(word) ⇒ Object

Checks if word was given correctly.

Raises:

  • (ArgumentError)


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