<commit_before>module Oxford
  module Learners
    module Dictionaries
      class English
        attr_reader :definition, :word, :page

        def initialize word
          @word = word
          @page = Nokogiri::HTML(open("http://www.oxfordlearnersdictionaries.com/definition/english/#{word}"))
          @definition = Hash.new
          parse
        end

        private
        def parse
          if @page.css(".n-g").count > 0
            multiple_definitions
          else
            unique_definition
          end
        end

        def unique_definition
          @definition[:definition] = @page.css(".d").text
        end

        def multiple_definitions
          @page.css(".n-g").each_with_index do |definition, index|
            @definition["definition_#{index}".to_sym] = definition.css(".d").text
          end
        end

      end
    end
  end
end

# definition.css(".x-g").each do |examples|<commit_msg>Add look_up method instead of parsing in initialize<commit_after>require 'nokogiri'
require 'open-uri'

module Oxford
  module Learners
    module Dictionaries
      class English
        attr_reader :definition, :url, :word, :page

        def initialize word
          @word = word
          @url = "http://www.oxfordlearnersdictionaries.com/definition/english/#{word}"
          @definition = Hash.new
        end

        def look_up
          @page = Nokogiri::HTML(open(@url))
          parse
        end

        private
        def parse
          if @page.css(".n-g").count > 0
            multiple_definitions
          else
            unique_definition
          end
        end

        def unique_definition
          @definition[:definition_0] = @page.css(".d").text
        end

        def multiple_definitions
          @page.css(".n-g").each_with_index do |definition, index|
            @definition["definition_#{index}".to_sym] = definition.css(".d").text
          end
        end

      end
    end
  end
end

# definition.css(".x-g").each do |examples|
{'fraction_non_alphanumeric': 0.10139165009940358, 'fraction_numerical': 0.0014910536779324055, 'mean_word_length': 1.8036211699164346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '966643', 'n_tokens_mistral': 565, 'n_tokens_neox': 545, 'n_words': 128}