Class: OxfordLearnersDictionaries::Definition
- Inherits:
-
Object
- Object
- OxfordLearnersDictionaries::Definition
- Defined in:
- lib/oxford_learners_dictionaries/definition.rb
Instance Attribute Summary collapse
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(page) ⇒ Definition
constructor
A new instance of Definition.
- #parse_multiple_definitions(index) ⇒ Object
- #parse_single_definition ⇒ Object
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
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
5 6 7 |
# File 'lib/oxford_learners_dictionaries/definition.rb', line 5 def examples @examples end |
#text ⇒ Object (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_definition ⇒ Object
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 |