Class: NetworkProfile::StackoverflowProfile

Inherits:
DefaultProfile show all
Defined in:
lib/network_profile/extractors/stackoverflow_profile.rb

Overview

Constant Summary collapse

SITES =
[
  ["https://stackoverflow.com", "stackoverflow", "Stack Overflow"],
  ["https://serverfault.com", "serverfault", "Server Fault"],
  ["https://superuser.com", "superuser", "Super User"],
  ["https://webapps.stackexchange.com", "webapps", "Web Applications"],
  ["https://gaming.stackexchange.com", "gaming", "Arqade"],
  ["https://webmasters.stackexchange.com", "webmasters", "Webmasters"],
  ["https://cooking.stackexchange.com", "cooking", "Seasoned Advice"],
  ["https://gamedev.stackexchange.com", "gamedev", "Game Development"],
  ["https://photo.stackexchange.com", "photo", "Photography"],
  ["https://stats.stackexchange.com", "stats", "Cross Validated"],
  ["https://math.stackexchange.com", "math", "Mathematics"],
  ["https://diy.stackexchange.com", "diy", "Home Improvement"],
  ["https://gis.stackexchange.com", "gis", "Geographic Information Systems"],
  ["https://tex.stackexchange.com", "tex", "TeX - LaTeX"],
  ["https://askubuntu.com", "askubuntu", "Ask Ubuntu"],
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DefaultProfile

all_types, auto_extractor_link_types, #data, #initialize, parse

Constructor Details

This class inherits a constructor from NetworkProfile::DefaultProfile

Class Method Details

.handle?(link) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 25

def self.handle?(link)
  SITES.any? { |s, _, _| link.include?(s + "/users/") }
end

Instance Method Details

#extra_dataObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 44

def extra_data
  {
    reputation: user_api.dig('reputation'),
    created: Time.at(user_api['creation_date']).to_date,
    location: user_api.dig('location'),
    site: site[2],
    site_logo: "https://cdn.sstatic.net/Sites/#{site[1]}/img/apple-touch-icon.png",
    tags: tags_api.map { |j| [j['tag_name'], j['answer_score'] + j['question_score']] }
  }
end

#imageObject



37
38
39
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 37

def image
  user_api['profile_image']
end

#siteObject



29
30
31
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 29

def site
  @site ||= SITES.find { |s, _, _| @link.include?(s) }
end

#textObject



41
42
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 41

def text
end

#titleObject



33
34
35
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 33

def title
  user_api['display_name']
end

#user_idObject



55
56
57
# File 'lib/network_profile/extractors/stackoverflow_profile.rb', line 55

def user_id
  URI.parse(@link).path[%r{/users/(\d+)/?}, 1]
end