Class: RepoSmallBadge::Configuration
- Inherits:
-
Object
- Object
- RepoSmallBadge::Configuration
- Defined in:
- lib/repo_small_badge/configuration.rb
Overview
Hidden class to handle the interface to configuration
Instance Method Summary collapse
- #background ⇒ Object
- #badge_height ⇒ Object
- #badge_middle ⇒ Object
- #badge_width ⇒ Object
- #filename(suffix = '') ⇒ Object
- #font ⇒ Object
- #font_size ⇒ Object
-
#initialize(config_hash) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge!(new_config) ⇒ Object
- #output_path ⇒ Object
- #rounded_edge_radius ⇒ Object
- #title(suffix) ⇒ Object
- #title_background ⇒ Object
- #title_color ⇒ Object
- #title_font ⇒ Object
- #title_font_size ⇒ Object
- #title_middle ⇒ Object
- #value_background ⇒ Object
- #value_color ⇒ Object
- #value_font ⇒ Object
- #value_font_size ⇒ Object
- #value_middle ⇒ Object
Constructor Details
#initialize(config_hash) ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 |
# File 'lib/repo_small_badge/configuration.rb', line 6 def initialize(config_hash) @config = config_hash end |
Instance Method Details
#background ⇒ Object
34 35 36 |
# File 'lib/repo_small_badge/configuration.rb', line 34 def background @config.fetch(:background, '#fff') end |
#badge_height ⇒ Object
70 71 72 |
# File 'lib/repo_small_badge/configuration.rb', line 70 def badge_height @config.fetch(:badge_height, 20).to_i end |
#badge_middle ⇒ Object
74 75 76 |
# File 'lib/repo_small_badge/configuration.rb', line 74 def badge_middle @config.fetch(:badge_middle, badge_width / 2).to_i end |
#badge_width ⇒ Object
66 67 68 |
# File 'lib/repo_small_badge/configuration.rb', line 66 def badge_width @config.fetch(:badge_width, 120).to_i end |
#filename(suffix = '') ⇒ Object
86 87 88 89 90 |
# File 'lib/repo_small_badge/configuration.rb', line 86 def filename(suffix = '') prefix = @config.fetch(:filename_prefix, 'badge') format = @config.fetch(:format, 'svg') "#{output_path}/#{prefix}_#{suffix}.#{format}" end |
#font ⇒ Object
50 51 52 |
# File 'lib/repo_small_badge/configuration.rb', line 50 def font @config.fetch(:font, 'Verdana,sans-serif') end |
#font_size ⇒ Object
54 55 56 |
# File 'lib/repo_small_badge/configuration.rb', line 54 def font_size @config.fetch(:font_size, 11).to_s end |
#merge!(new_config) ⇒ Object
10 11 12 |
# File 'lib/repo_small_badge/configuration.rb', line 10 def merge!(new_config) @config.merge!(new_config) end |
#output_path ⇒ Object
101 102 103 |
# File 'lib/repo_small_badge/configuration.rb', line 101 def output_path @config.fetch(:output_path, '.') end |
#rounded_edge_radius ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/repo_small_badge/configuration.rb', line 58 def rounded_edge_radius if @config.fetch(:rounded_border, true) @config.fetch(:rounded_edge_radius, '3') else 0 end end |
#title(suffix) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/repo_small_badge/configuration.rb', line 92 def title(suffix) prefix = @config.fetch(:title_prefix, '') if prefix.to_s.empty? suffix else "#{@config.fetch(:title_prefix, '')} #{suffix}" end end |
#title_background ⇒ Object
30 31 32 |
# File 'lib/repo_small_badge/configuration.rb', line 30 def title_background @config.fetch(:title_background, '#555') end |
#title_color ⇒ Object
46 47 48 |
# File 'lib/repo_small_badge/configuration.rb', line 46 def title_color @config.fetch(:title_color, '#fff') end |
#title_font ⇒ Object
38 39 40 |
# File 'lib/repo_small_badge/configuration.rb', line 38 def title_font @config.fetch(:title_font, font) end |
#title_font_size ⇒ Object
42 43 44 |
# File 'lib/repo_small_badge/configuration.rb', line 42 def title_font_size @config.fetch(:title_font_size, font_size) end |
#title_middle ⇒ Object
78 79 80 |
# File 'lib/repo_small_badge/configuration.rb', line 78 def title_middle badge_middle / 2 end |
#value_background ⇒ Object
14 15 16 |
# File 'lib/repo_small_badge/configuration.rb', line 14 def value_background @config.fetch(:value_background, '#4c1') end |
#value_color ⇒ Object
18 19 20 |
# File 'lib/repo_small_badge/configuration.rb', line 18 def value_color @config.fetch(:value_color, title_color) end |
#value_font ⇒ Object
22 23 24 |
# File 'lib/repo_small_badge/configuration.rb', line 22 def value_font @config.fetch(:value_font, font) end |
#value_font_size ⇒ Object
26 27 28 |
# File 'lib/repo_small_badge/configuration.rb', line 26 def value_font_size @config.fetch(:value_font_size, font_size) end |
#value_middle ⇒ Object
82 83 84 |
# File 'lib/repo_small_badge/configuration.rb', line 82 def value_middle badge_middle + (badge_width - badge_middle) / 2 end |