Class: OxfordLearnersDictionaries::English

Inherits:
Object
  • Object
show all
Defined in:
lib/oxford_learners_dictionaries/english.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ English

Returns a new instance of English.



8
9
10
11
12
13
14
# File 'lib/oxford_learners_dictionaries/english.rb', line 8

def initialize word
  formatted_word = word.strip.gsub(' ', '-') rescue ''
  param_word = formatted_word.gsub('-', '+')
  @url = "http://www.oxfordlearnersdictionaries.com/definition/english/#{formatted_word}?q=#{param_word}"
  @word = formatted_word
  @definition = Hash.new
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



6
7
8
# File 'lib/oxford_learners_dictionaries/english.rb', line 6

def definition
  @definition
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/oxford_learners_dictionaries/english.rb', line 6

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/oxford_learners_dictionaries/english.rb', line 6

def url
  @url
end

#wordObject (readonly)

Returns the value of attribute word.



6
7
8
# File 'lib/oxford_learners_dictionaries/english.rb', line 6

def word
  @word
end

Instance Method Details

#look_upObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/oxford_learners_dictionaries/english.rb', line 16

def look_up
  begin
    @page = Nokogiri::HTML(open(@url))
    @page.css('.idm-gs').remove
    parse
  rescue OpenURI::HTTPError
    nil
  end
  self.definition
end