Class: Manhunt::User
- Inherits:
-
Object
- Object
- Manhunt::User
- Defined in:
- lib/manhunt/user.rb
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#availability ⇒ Object
readonly
Returns the value of attribute availability.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#ethnicity ⇒ Object
readonly
Returns the value of attribute ethnicity.
-
#eyes ⇒ Object
readonly
Returns the value of attribute eyes.
-
#hair ⇒ Object
readonly
Returns the value of attribute hair.
-
#headline ⇒ Object
readonly
Returns the value of attribute headline.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#hiv ⇒ Object
readonly
Returns the value of attribute hiv.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#online ⇒ Object
readonly
Returns the value of attribute online.
-
#photos ⇒ Object
readonly
Returns the value of attribute photos.
-
#place ⇒ Object
readonly
Returns the value of attribute place.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
- .find(session, username) ⇒ Object
- .parse(session, document) ⇒ Object
- .parse_photos(user, photo_element) ⇒ Object
- .parse_user_id(document) ⇒ Object
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(session, document) ⇒ User
constructor
A new instance of User.
- #model_name ⇒ Object
- #parse_stats(stats_div) ⇒ Object
Constructor Details
#initialize(session, document) ⇒ User
Returns a new instance of User.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/manhunt/user.rb', line 28 def initialize(session, document) @session = session @username = (document/"#name").inner_text.strip @user_id = ManhuntUser.parse_user_id(document) @online = (document/".buddyOnline").any? @location = (document/"#profileLocation").inner_text.strip @body = (document/'#body').inner_text @headline = (document/'#headline').inner_text @html = document @photos = ManhuntUser.parse_photos(self, document/"#pics") parse_stats(document/"#stats") end |
Instance Attribute Details
#age ⇒ Object (readonly)
Returns the value of attribute age.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def age @age end |
#availability ⇒ Object (readonly)
Returns the value of attribute availability.
4 5 6 |
# File 'lib/manhunt/user.rb', line 4 def availability @availability end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
2 3 4 |
# File 'lib/manhunt/user.rb', line 2 def body @body end |
#build ⇒ Object (readonly)
Returns the value of attribute build.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def build @build end |
#ethnicity ⇒ Object (readonly)
Returns the value of attribute ethnicity.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def ethnicity @ethnicity end |
#eyes ⇒ Object (readonly)
Returns the value of attribute eyes.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def eyes @eyes end |
#hair ⇒ Object (readonly)
Returns the value of attribute hair.
4 5 6 |
# File 'lib/manhunt/user.rb', line 4 def hair @hair end |
#headline ⇒ Object (readonly)
Returns the value of attribute headline.
2 3 4 |
# File 'lib/manhunt/user.rb', line 2 def headline @headline end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def height @height end |
#hiv ⇒ Object (readonly)
Returns the value of attribute hiv.
4 5 6 |
# File 'lib/manhunt/user.rb', line 4 def hiv @hiv end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
4 5 6 |
# File 'lib/manhunt/user.rb', line 4 def html @html end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def location @location end |
#online ⇒ Object (readonly)
Returns the value of attribute online.
2 3 4 |
# File 'lib/manhunt/user.rb', line 2 def online @online end |
#photos ⇒ Object (readonly)
Returns the value of attribute photos.
2 3 4 |
# File 'lib/manhunt/user.rb', line 2 def photos @photos end |
#place ⇒ Object (readonly)
Returns the value of attribute place.
4 5 6 |
# File 'lib/manhunt/user.rb', line 4 def place @place end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
3 4 5 |
# File 'lib/manhunt/user.rb', line 3 def position @position end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
4 5 6 |
# File 'lib/manhunt/user.rb', line 4 def stats @stats end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
2 3 4 |
# File 'lib/manhunt/user.rb', line 2 def user_id @user_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
2 3 4 |
# File 'lib/manhunt/user.rb', line 2 def username @username end |
Class Method Details
.find(session, username) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/manhunt/user.rb', line 6 def self.find(session, username) uri = "/profile/#{username}" document = session.get_document(uri) do |text| # This little ugly hack fixes some majorly broken HTML on the site text.gsub(", \"med\", \"#largePic\")'; return false;>", ", \"med\", \"#largePic\"); return false;'>") end ManhuntUser.parse(session, document) end |
.parse(session, document) ⇒ Object
16 17 18 |
# File 'lib/manhunt/user.rb', line 16 def self.parse(session, document) user = ManhuntUser.new(session, document) end |
.parse_photos(user, photo_element) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/manhunt/user.rb', line 61 def self.parse_photos(user, photo_element) (photo_element/'div').map do |photo| photo_id = photo[:photoid].to_i ManhuntPhoto.new(user, photo_id) end end |
.parse_user_id(document) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/manhunt/user.rb', line 68 def self.parse_user_id(document) large_pic = (document/"#largePic").first if large_pic onclick = large_pic.attributes['onclick'] match = (/viewProfilePic\(this, (\d+)\); return false;/.match(onclick)) if match return match[1] end end nil end |
Instance Method Details
#id ⇒ Object
20 21 22 |
# File 'lib/manhunt/user.rb', line 20 def id user_id end |
#model_name ⇒ Object
24 25 26 |
# File 'lib/manhunt/user.rb', line 24 def model_name "user" end |
#parse_stats(stats_div) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/manhunt/user.rb', line 44 def parse_stats(stats_div) @stats = {} (stats_div/"div").each do |stat| title = (stat/"strong").inner_text.strip value = (stat/"p").inner_text.strip @stats[title] = value unless title.blank? end (stats_div/"label").each do |label| title = label.inner_text.strip value = label.next_sibling.inner_text.strip @stats[title] = value unless title.blank? end end |