Class: RunKeeperActivities::User

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username) ⇒ User

Returns a new instance of User.



15
16
17
18
# File 'lib/runkeeper_activities/user.rb', line 15

def initialize(username)
  @username = username
  @profile_url = Utils.runkeeper_url("/user/#{username}/profile")
end

Instance Attribute Details

#activitiesObject (readonly)

Returns the value of attribute activities.



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

def activities
  @activities
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#profile_image_urlObject (readonly)

Returns the value of attribute profile_image_url.



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

def profile_image_url
  @profile_image_url
end

#profile_urlObject (readonly)

Returns the value of attribute profile_url.



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

def profile_url
  @profile_url
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.find_by_username(username) ⇒ Object



10
11
12
# File 'lib/runkeeper_activities/user.rb', line 10

def find_by_username(username)
  RunKeeperActivities::User.new(username).tap { |_user| _user.get_profile }
end

Instance Method Details

#activities_urlObject



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

def activities_url
  @activities_url ||= Utils.runkeeper_url("/user/#{username}/activity")
end

#calories_unitObject



40
41
42
# File 'lib/runkeeper_activities/user.rb', line 40

def calories_unit
  @calories_unit ||= page.at_css('#statsCalories .unitText').text
end

#distance_unitObject



24
25
26
# File 'lib/runkeeper_activities/user.rb', line 24

def distance_unit
  @distance_unit ||= page.at_css('#statsDistance .unitText').text
end

#duration_unitObject



28
29
30
# File 'lib/runkeeper_activities/user.rb', line 28

def duration_unit
  @duration_unit ||= page.at_css('#statsDuration .unitText').text
end

#elevation_unitObject



44
45
46
# File 'lib/runkeeper_activities/user.rb', line 44

def elevation_unit
  @elevation_unit ||= page.at_css('#statsElevation .unitText').text
end

#get_profileObject



53
54
55
56
57
58
# File 'lib/runkeeper_activities/user.rb', line 53

def get_profile
  page.at_css('.profileBoxSmall img').tap do |_profile_image_tag|
    @name = _profile_image_tag['title']
    @profile_image_url = _profile_image_tag['src']
  end
end

#pace_unitObject



32
33
34
# File 'lib/runkeeper_activities/user.rb', line 32

def pace_unit
  @pace_unit ||= page.at_css('#statsPace .unitText').text
end

#pageObject



60
61
62
# File 'lib/runkeeper_activities/user.rb', line 60

def page
  @page ||= Nokogiri::HTML(open(activities_url))
end

#speed_unitObject



36
37
38
# File 'lib/runkeeper_activities/user.rb', line 36

def speed_unit
  @speed_unit ||= page.at_css('#statsSpeed .unitText').text
end