Class: RepoSmallBadge::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/repo_small_badge/configuration.rb

Overview

Hidden class to handle the interface to configuration

Instance Method Summary collapse

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

#backgroundObject



34
35
36
# File 'lib/repo_small_badge/configuration.rb', line 34

def background
  @config.fetch(:background, '#fff')
end

#badge_heightObject



70
71
72
# File 'lib/repo_small_badge/configuration.rb', line 70

def badge_height
  @config.fetch(:badge_height, 20).to_i
end

#badge_middleObject



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_widthObject



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

#fontObject



50
51
52
# File 'lib/repo_small_badge/configuration.rb', line 50

def font
  @config.fetch(:font, 'Verdana,sans-serif')
end

#font_sizeObject



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_pathObject



101
102
103
# File 'lib/repo_small_badge/configuration.rb', line 101

def output_path
  @config.fetch(:output_path, '.')
end

#rounded_edge_radiusObject



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_backgroundObject



30
31
32
# File 'lib/repo_small_badge/configuration.rb', line 30

def title_background
  @config.fetch(:title_background, '#555')
end

#title_colorObject



46
47
48
# File 'lib/repo_small_badge/configuration.rb', line 46

def title_color
  @config.fetch(:title_color, '#fff')
end

#title_fontObject



38
39
40
# File 'lib/repo_small_badge/configuration.rb', line 38

def title_font
  @config.fetch(:title_font, font)
end

#title_font_sizeObject



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_middleObject



78
79
80
# File 'lib/repo_small_badge/configuration.rb', line 78

def title_middle
  badge_middle / 2
end

#value_backgroundObject



14
15
16
# File 'lib/repo_small_badge/configuration.rb', line 14

def value_background
  @config.fetch(:value_background, '#4c1')
end

#value_colorObject



18
19
20
# File 'lib/repo_small_badge/configuration.rb', line 18

def value_color
  @config.fetch(:value_color, title_color)
end

#value_fontObject



22
23
24
# File 'lib/repo_small_badge/configuration.rb', line 22

def value_font
  @config.fetch(:value_font, font)
end

#value_font_sizeObject



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_middleObject



82
83
84
# File 'lib/repo_small_badge/configuration.rb', line 82

def value_middle
  badge_middle + (badge_width - badge_middle) / 2
end