Skip to content

Commit

Permalink
add support for color schemes, fixes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
akerl committed Oct 31, 2014
1 parent 00d50dc commit 7c90bcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions bin/githubchart
Expand Up @@ -35,6 +35,13 @@ OptionParser.new do |opts|

options[:data] = GithubStats::Data.new(parsed)
end
opts.on('-cSCHEME', '--colors SCHEME', 'Pick a color scheme') do |scheme|
if GithubChart::COLOR_SCHEMES.include? scheme.to_sym
options[:colors] = scheme.to_sym
else
fail 'Unknown color scheme provided'
end
end
opts.on_tail('-v', '--version', 'Show version') do
puts GithubChart::VERSION
exit
Expand Down
11 changes: 7 additions & 4 deletions lib/githubchart.rb
Expand Up @@ -38,9 +38,11 @@ def add_support(type)
end

##
# Default colors for gradient

COLORS = ['#eeeeee', '#d6e685', '#8cc665', '#44a340', '#1e6823']
# Color schemes for gradient
COLOR_SCHEMES = {
default: ['#eeeeee', '#d6e685', '#8cc665', '#44a340', '#1e6823'],
halloween: ['#EEEEEE', '#FFEE4A', '#FFC501', '#FE9600', '#03001C']
}

##
# Object for parsing and outputing Github stats data
Expand All @@ -56,7 +58,8 @@ class Chart
def initialize(params = {})
params = { user: params } unless params.is_a? Hash
@stats = params.fetch(:data) { GithubStats.new(params[:user]).data }
@colors = params[:colors] || GithubChart::COLORS
@colors = params[:colors] || :default
@colors = COLOR_SCHEMES[@colors] unless @colors.is_a? Array
end

private
Expand Down
4 changes: 3 additions & 1 deletion spec/githubchart_spec.rb
Expand Up @@ -32,7 +32,9 @@
expect(GithubChart.new(data: data).stats).to eql data
end
it 'creates a data object when not provided' do
expect(GithubChart.new(username: 'fly').stats).to be_an_instance_of GithubStats::Data
expect(
GithubChart.new(username: 'fly').stats
).to be_an_instance_of GithubStats::Data
end
end
end
Expand Down

0 comments on commit 7c90bcc

Please sign in to comment.