lib/githubchart.rb in githubchart-2.1.0 vs lib/githubchart.rb in githubchart-3.1.0

- old
+ new

@@ -38,11 +38,12 @@ end ## # Color schemes for gradient COLOR_SCHEMES = { - default: ['#eeeeee', '#d6e685', '#8cc665', '#44a340', '#1e6823'], + default: ['#eeeeee', '#c6e48b', '#7bc96f', '#239a3b', '#196127'], + old: ['#eeeeee', '#d6e685', '#8cc665', '#44a340', '#1e6823'], halloween: ['#EEEEEE', '#FFEE4A', '#FFC501', '#FE9600', '#03001C'] }.freeze ## # Object for parsing and outputing Github stats data @@ -55,11 +56,11 @@ # Passes the username through to GithubStats # Uses colors rather than default, if provided def initialize(params = {}) params = { user: params } unless params.is_a? Hash - @stats = params.fetch(:data) { GithubStats.new(params[:user]).data } + @stats = load_stats(params[:data], params[:user]) @colors = params[:colors] || :default @colors = COLOR_SCHEMES[@colors] unless @colors.is_a? Array end def render(type) @@ -68,9 +69,20 @@ end send("render_#{type}".to_sym) end private + + ## + # Load stats from provided arg or github + + def load_stats(data, user) + return data if data + raise('No data or user provided') unless user + stats = GithubStats.new(user).data + raise("Failed to find data for #{user} on GitHub") unless stats + stats + end ## # Convert the data into a matrix of weeks # The fill value is used to pad the front and backdd