class GitScrap
Constants
- GITHUB_URL
- TILE_COLOR
Attributes
tile_table[R]
year[W]
Public Class Methods
new(user)
click to toggle source
# File lib/gitgrass/git_scrap.rb, line 16 def initialize(user) @user = user @tile_table = Array.new(7) { [] } end
Public Instance Methods
get_commit()
click to toggle source
# File lib/gitgrass/git_scrap.rb, line 21 def get_commit url = @year ? "#{GITHUB_URL}#{@user}?tab=overview&from=#{@year}-01-01&to=#{@year}-12-31" : "#{GITHUB_URL}#{@user}" html = URI(url) body = html.read body.scan(/<rect.*data-count=.*data-level="(0|1|2|3|4)".*>/) end
make_grass_table()
click to toggle source
# File lib/gitgrass/git_scrap.rb, line 28 def make_grass_table commit_data = self.get_commit().flatten if @year Date.new(@year, 1, 1).wday.times do |n| commit_data.unshift("dummy") end end 0.step(commit_data.length - 1, 7) do |index| oneweek_tile = commit_data.slice(index, 7) oneweek_tile.each_with_index do |item, index| @tile_table[index] << TILE_COLOR[item.to_sym] end end end