Class: OxfordLearnersDictionaries::Definition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ Definition

Returns a new instance of Definition.



7
8
9
10
# File 'lib/oxford_learners_dictionaries/definition.rb', line 7

def initialize page
  @page = page
  @examples = Array.new
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



5
6
7
# File 'lib/oxford_learners_dictionaries/definition.rb', line 5

def examples
  @examples
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/oxford_learners_dictionaries/definition.rb', line 5

def text
  @text
end

Instance Method Details

#parse_multiple_definitions(index) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/oxford_learners_dictionaries/definition.rb', line 19

def parse_multiple_definitions index
  @text = @page.css('.def')[index].text
  return self if @page.css('.x-gs')[index].nil?

  @page.css('.x-gs')[index].css('.x-g').each do |example|
    @examples.push(::OxfordLearnersDictionaries::Example.new(example))
  end
  self
end

#parse_single_definitionObject



12
13
14
15
16
17
# File 'lib/oxford_learners_dictionaries/definition.rb', line 12

def parse_single_definition
  text =  @page.css('.def')
  @text = text.count > 0 ? text[0].text : text.text
  @examples.push(::OxfordLearnersDictionaries::Example.new(@page.css('.x-g')))
  self
end