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
15
16
17
# File 'lib/oxford_learners_dictionaries/english.rb', line 8

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

  @urls = [ main_url, main_url.gsub('?q=', '1?q=') ]
  @word = formatted_word
  @definition = Array.new
  self
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

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
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

#urlsObject (readonly)

Returns the value of attribute urls.



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

def urls
  @urls
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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oxford_learners_dictionaries/english.rb', line 19

def look_up
  @urls.each do |url|
    begin
      @page = Nokogiri::HTML(open(url))
      break
    rescue OpenURI::HTTPError
      @page = nil
    end
  end
  return nil if @page.nil?

  parse
  self
end