Class: NetworkProfile::UpworkProfile

Inherits:
DefaultProfile show all
Defined in:
lib/network_profile/extractors/upwork_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)


6
7
8
# File 'lib/network_profile/extractors/upwork_profile.rb', line 6

def self.handle?(link)
  link[%r{upwork.com/o/profiles/users/.+}]
end

Instance Method Details

#extra_dataObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/network_profile/extractors/upwork_profile.rb', line 27

def extra_data
  profile = php_vars.dig('profile')
  rate = profile.dig('stats', 'hourlyRate')
  {
    country: profile.dig('profile', 'location').yield_self { |v| "#{v['city']}, #{v['country']}" },
    hours: profile.dig('stats', 'totalHours').floor,
    jobs: profile.dig('stats', 'totalJobsWorked').floor,
    rating: profile.dig('stats', 'rating').round(2),
    hourly_rate: "#{rate['amount']} #{rate['currencyCode']}",
    english_level: profile['stats']['englishLevel'],
    hire_again: profile.dig('stats', 'hireAgainPercentage'),
    skills: profile.dig('profile', 'skills').map { |i| i['prettyName'] }
  }
end

#php_varsObject



18
19
20
21
22
23
24
25
# File 'lib/network_profile/extractors/upwork_profile.rb', line 18

def php_vars
  @php_vars ||=
    begin
      t = doc.search('script').find { |i| i && i.text['PROFILE_RESPONSE'] }.text
      t.remove!(/window.PROFILE_RESPONSE=.*summary:/)
      JSON.parse(t.remove(/\}$/))
    end
end

#textObject



14
15
16
# File 'lib/network_profile/extractors/upwork_profile.rb', line 14

def text
  doc.at('h2 strong').text
end

#titleObject



10
11
12
# File 'lib/network_profile/extractors/upwork_profile.rb', line 10

def title
  php_vars.dig('profile', 'profile', 'name')
end