Class: Dict::Wiktionary
- Inherits:
-
Dictionary
- Object
- Dictionary
- Dict::Wiktionary
- Defined in:
- lib/dict/wiktionary.rb
Overview
Class fetching translations of given word from wiktionary.org.
Instance Method Summary collapse
- #get_html(url) ⇒ Object
-
#translate ⇒ Object
Returns an Dict::Result object.
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 |
#translate ⇒ Object
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 |