Sha256: 3ba8e88df279bd18c26109ed84af7f2ec390a7b790672dc6619de9ef5bf286b7

Contents?: true

Size: 603 Bytes

Versions: 2

Compression:

Stored size: 603 Bytes

Contents

require 'oga'
require 'open-uri'
require 'date'

module CodeBadges
  # This class get the user account as an input
  # return a hash of user's badges information
  class CodecademyCourses
    MAIN_URL = 'https://www.codecademy.com'
    XPATH_COURSES = "//div[h5/strong/text()='Learn To Code']/div/div/ul/li/a"

    def courses
      @courses ||= extract_main_courses
    end

    private

    def extract_main_courses
      doc = Oga.parse_html(open(MAIN_URL))
      doc.xpath(XPATH_COURSES).map do |course|
        [course.text, URI.join(MAIN_URL, course.get('href'))]
      end.to_h
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codebadges-2.0.1 lib/codebadges/courses.rb
codebadges-2.0.0 lib/codebadges/courses.rb