Class: Manhunt::User

Inherits:
Object
  • Object
show all
Defined in:
lib/manhunt/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#ageObject (readonly)

Returns the value of attribute age.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def age
  @age
end

#availabilityObject (readonly)

Returns the value of attribute availability.



4
5
6
# File 'lib/manhunt/user.rb', line 4

def availability
  @availability
end

#bodyObject (readonly)

Returns the value of attribute body.



2
3
4
# File 'lib/manhunt/user.rb', line 2

def body
  @body
end

#buildObject (readonly)

Returns the value of attribute build.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def build
  @build
end

#ethnicityObject (readonly)

Returns the value of attribute ethnicity.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def ethnicity
  @ethnicity
end

#eyesObject (readonly)

Returns the value of attribute eyes.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def eyes
  @eyes
end

#hairObject (readonly)

Returns the value of attribute hair.



4
5
6
# File 'lib/manhunt/user.rb', line 4

def hair
  @hair
end

#headlineObject (readonly)

Returns the value of attribute headline.



2
3
4
# File 'lib/manhunt/user.rb', line 2

def headline
  @headline
end

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def height
  @height
end

#hivObject (readonly)

Returns the value of attribute hiv.



4
5
6
# File 'lib/manhunt/user.rb', line 4

def hiv
  @hiv
end

#htmlObject (readonly)

Returns the value of attribute html.



4
5
6
# File 'lib/manhunt/user.rb', line 4

def html
  @html
end

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def location
  @location
end

#onlineObject (readonly)

Returns the value of attribute online.



2
3
4
# File 'lib/manhunt/user.rb', line 2

def online
  @online
end

#photosObject (readonly)

Returns the value of attribute photos.



2
3
4
# File 'lib/manhunt/user.rb', line 2

def photos
  @photos
end

#placeObject (readonly)

Returns the value of attribute place.



4
5
6
# File 'lib/manhunt/user.rb', line 4

def place
  @place
end

#positionObject (readonly)

Returns the value of attribute position.



3
4
5
# File 'lib/manhunt/user.rb', line 3

def position
  @position
end

#statsObject (readonly)

Returns the value of attribute stats.



4
5
6
# File 'lib/manhunt/user.rb', line 4

def stats
  @stats
end

#user_idObject (readonly)

Returns the value of attribute user_id.



2
3
4
# File 'lib/manhunt/user.rb', line 2

def user_id
  @user_id
end

#usernameObject (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

#idObject



20
21
22
# File 'lib/manhunt/user.rb', line 20

def id
  user_id
end

#model_nameObject



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