Class: AsciiPaint::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ascii_paint/config.rb

Defined Under Namespace

Modules: Default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Config

Returns a new instance of Config.



24
25
26
27
# File 'lib/ascii_paint/config.rb', line 24

def initialize(settings = {})
  reset!
  set_options(settings)
end

Instance Attribute Details

#character_heightObject

The vertical size in pixels of the rectangle that replaces a single character during painting.



20
21
22
# File 'lib/ascii_paint/config.rb', line 20

def character_height
  @character_height
end

#character_widthObject

The horizontal size in pixels of the rectangle that replaces a single character during painting.



16
17
18
# File 'lib/ascii_paint/config.rb', line 16

def character_width
  @character_width
end

#color_mapObject

Returns the value of attribute color_map.



22
23
24
# File 'lib/ascii_paint/config.rb', line 22

def color_map
  @color_map
end

Instance Method Details

#border_colorObject



78
79
80
# File 'lib/ascii_paint/config.rb', line 78

def border_color
  TRANSPARENT
end

#characters_to_pixels(x, y) ⇒ Object



57
58
59
# 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) ⇒ void

This method returns an undefined value.

Set the color to paint over characters whose color hasn’t been defined by the color map.

Parameters:

  • default_color (Symbol)

    the default color to replace characters without a specified color.



53
54
55
# 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

#reset!Object



82
83
84
85
86
87
88
89
90
91
92
# 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) ⇒ Object

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

Parameters:

  • options (Hash<Symbol, value>)

    settings mapping from attribute name to value.

Returns:

  • self



70
71
72
73
74
75
76
# 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