Module: GitHub::Calendar
Instance Method Summary collapse
-
#get_average_day(user) ⇒ Integer
Gets the average daily number of contributions by the user.
-
#get_average_month(user) ⇒ Integer
Gets the average monthly number of contributions by the user.
-
#get_average_week(user) ⇒ Integer
Gets the average weekly number of contributions by the user.
-
#get_daily(user) ⇒ Hash
Gets the daily contribution count for the past year.
-
#get_monthly(user) ⇒ Hash
Gets the monthly contribution count for the past year.
-
#get_total_year(user) ⇒ Integer
Gets the total number of contributions for the past year.
-
#get_weekly(user) ⇒ Hash
Gets the weekly contribution count for the past year.
Instance Method Details
#get_average_day(user) ⇒ Integer
Gets the average daily number of contributions by the user.
105 106 107 108 |
# File 'lib/github/calendar.rb', line 105 def get_average_day(user) daily = get_daily(user) get_average(daily) end |
#get_average_month(user) ⇒ Integer
Gets the average monthly number of contributions by the user.
113 114 115 116 |
# File 'lib/github/calendar.rb', line 113 def get_average_month(user) monthly = get_monthly(user) get_average(monthly) end |
#get_average_week(user) ⇒ Integer
Gets the average weekly number of contributions by the user.
97 98 99 100 |
# File 'lib/github/calendar.rb', line 97 def get_average_week(user) weekly = get_weekly(user) get_average(weekly) end |
#get_daily(user) ⇒ Hash
Gets the daily contribution count for the past year.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/github/calendar.rb', line 50 def get_daily(user) weeks = get_calendar(user) ret = {} count = 0 weeks.each do |k| k.children.each do |day| val = day.attribute('data-count').value.to_i ret[count] = val count += 1 end end ret end |
#get_monthly(user) ⇒ Hash
Gets the monthly contribution count for the past year. e.g., 01 is January and 12 is December.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/github/calendar.rb', line 68 def get_monthly(user) weeks = get_calendar(user) ret = { '01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0, '07' => 0, '08' => 0, '09' => 0, '10' => 0, '11' => 0, '12' => 0 } weeks.each do |k| k.children.each do |day| date = day.attribute('data-date').value.split('-')[1] count = day.attribute('data-count').value ret[date] += count.to_i end end ret end |
#get_total_year(user) ⇒ Integer
Gets the total number of contributions for the past year.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/github/calendar.rb', line 14 def get_total_year(user) source = get_page_source(user) headers = source.css('h2') string = nil headers.each do |i| # Strip excess whitespace and newlines header_text = i.text.gsub(/(\s+|\n)/, ' ') if /contributions in the last year/ =~ header_text string = header_text.to_i_separated break end end string || 0 end |
#get_weekly(user) ⇒ Hash
Gets the weekly contribution count for the past year.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/github/calendar.rb', line 32 def get_weekly(user) weeks = get_calendar(user) ret = {} count = 0 weeks.each do |k| week_data = 0 k.children.each do |element| week_data += element.attribute('data-count').value.to_i end ret[count] = week_data count += 1 end ret end |