Class: GithubApi::FollowersPage

Inherits:
Object
  • Object
show all
Defined in:
lib/unofficial-github-api/github_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_name, page_number) ⇒ FollowersPage

Returns a new instance of FollowersPage.



44
45
46
47
# File 'lib/unofficial-github-api/github_api.rb', line 44

def initialize(user_name, page_number)
  @name = user_name
  @page = page_number
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



43
44
45
# File 'lib/unofficial-github-api/github_api.rb', line 43

def name
  @name
end

#pageObject (readonly)

Returns the value of attribute page.



43
44
45
# File 'lib/unofficial-github-api/github_api.rb', line 43

def page
  @page
end

Instance Method Details

#contentObject



49
50
51
# File 'lib/unofficial-github-api/github_api.rb', line 49

def content
  @content ||= Nokogiri::HTML(open("https://github.com/#{name}/followers?page=#{page}"))
end

#follower_exists?(i) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/unofficial-github-api/github_api.rb', line 61

def follower_exists?(i)
  follower_row(i).to_ary != []
end

#follower_name(i) ⇒ Object



57
58
59
# File 'lib/unofficial-github-api/github_api.rb', line 57

def follower_name(i)
  follower_row(i).children[1].attributes['href'].value.gsub(/\//,'')
end

#follower_row(i) ⇒ Object



53
54
55
# File 'lib/unofficial-github-api/github_api.rb', line 53

def follower_row(i)
  content.xpath("//*[@id='site-container']/div[2]/ol/li[#{i}]")
end

#followers_listObject



65
66
67
68
69
70
71
72
# File 'lib/unofficial-github-api/github_api.rb', line 65

def followers_list
  i, list = 1, []
  while follower_exists?(i)
    list << follower_name(i)
    i += 1
  end
  list
end