Permalink
Browse files

add support for color schemes, fixes #32

  • Loading branch information...
akerl committed Oct 31, 2014
1 parent 00d50dc commit 7c90bcc9b07965cb978a11a29981a03433aa7ab2
Showing with 17 additions and 5 deletions.
  1. +7 −0 bin/githubchart
  2. +7 −4 lib/githubchart.rb
  3. +3 −1 spec/githubchart_spec.rb
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 7c90bcc

Please sign in to comment.