Sha256: 19e1147c73df49388df7dcc9567db332a865f491a790b563f6b3424ad986c538

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'open-uri'
require 'nokogiri'

##
# Module for parsing Linode employee info
module Linodians
  DATA_URL = 'https://www.linode.com/employees'
  PHOTO_URL = 'https://www.linode.com/media/images/employees/%s.png'

  class << self
    ##
    # Insert a helper .new() method for creating a new Group object
    def new(*args)
      self::Group.new(*args)
    end

    def download_data
      Nokogiri::HTML(open(DATA_URL)).css('.employee-display').map do |block|
        data = parse_user(block).merge parse_social(block)
        Employee.new data
      end
    end

    private

    def parse_user(block)
      {
        username: block.at_css('img')['img-name'],
        fullname: block.at_css('strong').text,
        title: block.at_css('small').text
      }
    end

    def parse_social(block)
      links = block.css('a.employee-link').map do |link|
        # Social site name from CSS class, link target
        [link[:class].split.last.split('-').last.to_sym, link['href']]
      end.to_h
      links.merge(social: links.keys)
    end
  end
end

require 'linodians/version'
require 'linodians/employee'
require 'linodians/group'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
linodians-0.0.4 lib/linodians.rb
linodians-0.0.3 lib/linodians.rb