Class: Dict::Wiktionary

Inherits:
Dictionary show all
Defined in:
lib/dict/wiktionary.rb

Overview

Class fetching translations of given word from wiktionary.org.

Instance Method Summary collapse

Methods inherited from Dictionary

#check_arguments, #initialize, message, #uri

Constructor Details

This class inherits a constructor from Dict::Dictionary

Instance Method Details

#get_html(url) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/dict/wiktionary.rb', line 20

def get_html(url)
  begin
    Nokogiri::HTML(open(URI.encode(url)))
  rescue OpenURI::HTTPError
    raise Dictionary::ConnectError
  end
end

#translateObject

Returns an Dict::Result object.



11
12
13
14
15
16
17
18
# File 'lib/dict/wiktionary.rb', line 11

def translate
  translations.each do |translation|
    @result.add_translation(@result.term, translation.gsub(/(\s[^|\s]+\|)/,' '))
    examples(translation).each { |example| @result.add_example(translation, example) }
  end

  @result
end