Class: OKCupid::Profile
- Inherits:
-
Object
- Object
- OKCupid::Profile
- Defined in:
- lib/lonely_coder/profile.rb
Instance Attribute Summary collapse
-
#age ⇒ Object
Returns the value of attribute age.
-
#body_type ⇒ Object
extended profile details.
-
#diet ⇒ Object
extended profile details.
-
#drinks ⇒ Object
extended profile details.
-
#drugs ⇒ Object
extended profile details.
-
#education ⇒ Object
extended profile details.
-
#enemy ⇒ Object
Returns the value of attribute enemy.
-
#ethnicity ⇒ Object
extended profile details.
-
#friend ⇒ Object
Returns the value of attribute friend.
-
#height ⇒ Object
extended profile details.
-
#income ⇒ Object
extended profile details.
-
#job ⇒ Object
extended profile details.
-
#last_online ⇒ Object
extended profile details.
-
#location ⇒ Object
Returns the value of attribute location.
-
#match ⇒ Object
Returns the value of attribute match.
-
#offspring ⇒ Object
extended profile details.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#pets ⇒ Object
extended profile details.
-
#profile_thumb_urls ⇒ Object
extended profile details.
-
#religion ⇒ Object
extended profile details.
-
#sex ⇒ Object
Returns the value of attribute sex.
-
#sign ⇒ Object
extended profile details.
-
#single ⇒ Object
Returns the value of attribute single.
-
#small_avatar_url ⇒ Object
Returns the value of attribute small_avatar_url.
-
#smokes ⇒ Object
extended profile details.
-
#speaks ⇒ Object
extended profile details.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
- .by_username(username, browser) ⇒ Object
-
.from_search_result(html) ⇒ Object
Scraping is never pretty.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attributes) ⇒ Profile
constructor
A new instance of Profile.
Constructor Details
#initialize(attributes) ⇒ Profile
Returns a new instance of Profile.
89 90 91 92 93 |
# File 'lib/lonely_coder/profile.rb', line 89 def initialize(attributes) attributes.each do |attr,val| self.send("#{attr}=", val) end end |
Instance Attribute Details
#age ⇒ Object
Returns the value of attribute age.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def age @age end |
#body_type ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def body_type @body_type end |
#diet ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def diet @diet end |
#drinks ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def drinks @drinks end |
#drugs ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def drugs @drugs end |
#education ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def education @education end |
#enemy ⇒ Object
Returns the value of attribute enemy.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def enemy @enemy end |
#ethnicity ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def ethnicity @ethnicity end |
#friend ⇒ Object
Returns the value of attribute friend.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def friend @friend end |
#height ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def height @height end |
#income ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def income @income end |
#job ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def job @job end |
#last_online ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def last_online @last_online end |
#location ⇒ Object
Returns the value of attribute location.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def location @location end |
#match ⇒ Object
Returns the value of attribute match.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def match @match end |
#offspring ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def offspring @offspring end |
#orientation ⇒ Object
Returns the value of attribute orientation.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def orientation @orientation end |
#pets ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def pets @pets end |
#profile_thumb_urls ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def profile_thumb_urls @profile_thumb_urls end |
#religion ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def religion @religion end |
#sex ⇒ Object
Returns the value of attribute sex.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def sex @sex end |
#sign ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def sign @sign end |
#single ⇒ Object
Returns the value of attribute single.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def single @single end |
#small_avatar_url ⇒ Object
Returns the value of attribute small_avatar_url.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def small_avatar_url @small_avatar_url end |
#smokes ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def smokes @smokes end |
#speaks ⇒ Object
extended profile details
13 14 15 |
# File 'lib/lonely_coder/profile.rb', line 13 def speaks @speaks end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/lonely_coder/profile.rb', line 9 def username @username end |
Class Method Details
.by_username(username, browser) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/lonely_coder/profile.rb', line 46 def Profile.by_username(username, browser) html = browser.get("http://www.okcupid.com/profile/#{username}") percents = html.search('#percentages') match = percents.search('span.match').text.to_i friend = percents.search('span.friend').text.to_i enemy = percents.search('span.enemy').text.to_i basic = html.search('#aso_loc') age = basic.search('#ajax_age').text sex = basic.search('#ajax_gender').text orientation = basic.search('#ajax_orientation').text single = basic.search('#ajax_status').text location = basic.search('#ajax_location').text profile_thumb_urls = html.search('#profile_thumbs img').collect {|img| img.attribute('src').value} attributes = { username: username, match: match, friend: friend, enemy: enemy, age: age, sex: sex, orientation: orientation, location: location, single: single, profile_thumb_urls: profile_thumb_urls } details_div = html.search('#profile_details dl') details_div.each do |node| value = OKCupid.strip(node.search('dd').text) next if value == '—' attr_name = node.search('dt').text.downcase.gsub(' ','_') attributes[attr_name] = value end self.new(attributes) end |
.from_search_result(html) ⇒ Object
Scraping is never pretty.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lonely_coder/profile.rb', line 19 def self.from_search_result(html) username = html.search('span.username').text age, sex, orientation, single = html.search('p.aso').text.split('/') percents = html.search('div.percentages') match = percents.search('p.match .percentage').text.to_i friend = percents.search('p.friend .percentage').text.to_i enemy = percents.search('p.enemy .percentage').text.to_i location = html.search('p.location').text small_avatar_url = html.search('a.user_image img').attribute('src').value OKCupid::Profile.new({ username: username, age: OKCupid.strip(age), sex: OKCupid.strip(sex), orientation: OKCupid.strip(orientation), single: OKCupid.strip(single), match: match, friend: friend, enemy: enemy, location: location, small_avatar_url: small_avatar_url }) end |
Instance Method Details
#==(other) ⇒ Object
95 96 97 |
# File 'lib/lonely_coder/profile.rb', line 95 def ==(other) self.username == other.username end |
#eql?(other) ⇒ Boolean
99 100 101 |
# File 'lib/lonely_coder/profile.rb', line 99 def eql?(other) self.username == other.username end |
#hash ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/lonely_coder/profile.rb', line 103 def hash if self.username self.username.hash else super end end |