Class: NetworkProfile::ResearchgateProfile

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DefaultProfile

all_types, auto_extractor_link_types, #data, #image, #initialize, parse

Constructor Details

This class inherits a constructor from NetworkProfile::DefaultProfile

Class Method Details

.handle?(link) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/network_profile/extractors/researchgate_profile.rb', line 5

def self.handle?(link)
  link['researchgate.net/profile/']
end

Instance Method Details

#extra_dataObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/network_profile/extractors/researchgate_profile.rb', line 35

def extra_data
  card = doc.at(".profile-content-item .nova-c-card")
  return {} unless card

  items, reads, citations = card.
    search(".nova-o-grid__column").
    map { |col| col.search('.nova-e-text').map(&:text) }.
    map(&:first).map { |i| i.gsub(',', '').to_i }

  { items: items, reads: reads, citations: citations, last_item: last_item }
end

#json_ldObject



9
10
11
12
13
14
15
16
# File 'lib/network_profile/extractors/researchgate_profile.rb', line 9

def json_ld
  original = super
  if original['@graph']
    original['@graph'].first
  else
    original
  end
end

#last_itemObject



26
27
28
29
30
31
32
33
# File 'lib/network_profile/extractors/researchgate_profile.rb', line 26

def last_item
  item = rdf.find { |_, v| v['type'].to_s['ScholarlyArticle'] }.last
  return unless item

  title = item.dig('<http://schema.org/headline>', 0)
  date = item.dig('<http://schema.org/datePublished>', 0)
  "#{title} (#{date})"
end

#textObject



22
23
24
# File 'lib/network_profile/extractors/researchgate_profile.rb', line 22

def text
  json_ld.dig('affiliation', 'name') || doc.at('.org')&.text
end

#titleObject



18
19
20
# File 'lib/network_profile/extractors/researchgate_profile.rb', line 18

def title
  json_ld['name']
end