class AsciiPaint::Config
Constants
- SPECIAL_SYMBOL_MAP
- TRANSPARENT
Attributes
character_height[RW]
The vertical size in pixels of the rectangle that replaces a single character during painting.
character_width[RW]
The horizontal size in pixels of the rectangle that replaces a single character during painting.
color_map[RW]
Public Class Methods
new(settings = {})
click to toggle source
# File lib/ascii_paint/config.rb, line 24 def initialize(settings = {}) reset! set_options(settings) end
Also aliased as: default
Public Instance Methods
border_color()
click to toggle source
# File lib/ascii_paint/config.rb, line 78 def border_color TRANSPARENT end
characters_to_pixels(x, y)
click to toggle source
# File lib/ascii_paint/config.rb, line 57 def characters_to_pixels(x, y) [x * character_width, y * character_height] end
color_for_undefined_character=(default_color)
click to toggle source
Set the color to paint over characters whose color hasn’t been defined by the color map.
@param default_color [Symbol]
the default color to replace characters without a specified color.
@return [void]
# File lib/ascii_paint/config.rb, line 53 def color_for_undefined_character=(default_color) color_map.default = replacement_for_special_symbol(default_color) end
color_map=(hash)
click to toggle source
Merge new mappings into the color map.
The color map specifies which color paints over each character. For example,
config.color_map = { 'a' => :blue }
tells ASCII paint to replace the character ‘a’ with the color blue.
@param hash [Hash<String, Symbol>]
the new mappings to be merged into the color map.
@return [void]
# File lib/ascii_paint/config.rb, line 42 def color_map=(hash) replace_special_symbols!(hash) @color_map = color_map.merge(hash) end
reset!()
click to toggle source
# File lib/ascii_paint/config.rb, line 82 def reset! @character_height = Default::CHARACTER_HEIGHT @character_width = Default::CHARACTER_WIDTH @color_map = begin map = Default::COLOR_MAP.dup map.default = Default::COLOR_FOR_UNDEFINED_CHARACTER replace_special_symbols!(map) map end end
set_options(options)
click to toggle source
Set configuration options using a hash instead of using method calls. For example,
config.set_options({character_width: 10})
is equivalent to
config.character_width = 10
@param options [Hash<Symbol, value>]
settings mapping from attribute name to value.
@return self
# File lib/ascii_paint/config.rb, line 70 def set_options(options) options.each do |key, value| mutator_name = "#{key}=" self.send(mutator_name, value) end self end
Private Instance Methods
replace_special_symbols!(hash)
click to toggle source
# File lib/ascii_paint/config.rb, line 96 def replace_special_symbols!(hash) hash.each do |char, color_sym| hash[char] = replacement_for_special_symbol(color_sym) end end
replacement_for_special_symbol(symbol)
click to toggle source
# File lib/ascii_paint/config.rb, line 102 def replacement_for_special_symbol(symbol) SPECIAL_SYMBOL_MAP[symbol] || symbol end