Class: Tart::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/tart/builder.rb

Constant Summary collapse

PIXEL =
"██"
SPACE =
"  "

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
13
# File 'lib/tart/builder.rb', line 8

def initialize(filename, options={})
  options = ({ :pixel_char => PIXEL, :space_char => SPACE}).merge(options)
  @filename = filename
  @pixel = options[:pixel_char]
  @space = options[:space_char]
end

Instance Method Details

#draw(char) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tart/builder.rb', line 27

def draw(char)
  case char
  when "." then space

  when "K" then pixel :black
  when "R" then pixel :red
  when "G" then pixel :green
  when "Y" then pixel :yellow
  when "B" then pixel :blue
  when "M" then pixel :magenta
  when "C" then pixel :cyan
  when "W" then pixel :white

  when "k" then pixel :light_black
  when "r" then pixel :light_red
  when "g" then pixel :light_green
  when "y" then pixel :light_yellow
  when "b" then pixel :light_blue
  when "m" then pixel :light_magenta
  when "c" then pixel :light_cyan
  when "w" then pixel :light_white

  when "X","x" then pixel :default
  end
end

#pixel(color) ⇒ Object



53
54
55
# File 'lib/tart/builder.rb', line 53

def pixel(color)
  @pixel.colorize(color)
end

#processObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tart/builder.rb', line 15

def process
  output_str = ""
  IO.foreach(@filename) do |l|
    l.split('').each do |char|
      output_str << draw(char).to_s
    end
    output_str << "\n"
  end

  output_str
end

#spaceObject



57
58
59
# File 'lib/tart/builder.rb', line 57

def space
  @space
end