Class: Cahdmaker::Maker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Maker

Returns a new instance of Maker.



9
10
11
# File 'lib/cahdmaker.rb', line 9

def initialize(opts={})
  @opts = { text_size: 60, blank_size: 10, font: 'Helvetica-Bold' }.merge(opts)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



7
8
9
# File 'lib/cahdmaker.rb', line 7

def opts
  @opts
end

Instance Method Details

#black(text, pick = 1, &block) ⇒ Object



13
14
15
# File 'lib/cahdmaker.rb', line 13

def black(text, pick=1, &block)
  make_card(text, "Black#{pick}", &block)
end

#black2(text, &block) ⇒ Object



17
18
19
# File 'lib/cahdmaker.rb', line 17

def black2(text, &block)
  black(text, 2, &block)
end

#black3(text, &block) ⇒ Object



21
22
23
# File 'lib/cahdmaker.rb', line 21

def black3(text, &block)
  black(text, 3, &block)
end

#make_card(text, source_card) ⇒ Object



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

def make_card(text, source_card)
  text_size = opts[:text_size].to_i
  color = source_card =~ /White/i ? 'black' : 'white'
  font = opts[:font]
  text.gsub! /\b_+\b/, ('_' * opts[:blank_size])

  cap = Magick::Image.read(%{caption:#{text}}) do
    self.size = '600x'
    self.background_color = 'transparent'
    self.pointsize = text_size.to_f
    self['interline-spacing'] = (text_size/3).to_f
    self.font = font
    self.fill = color
  end.first

  img = Magick::Image.read(File.expand_path("../../cards/CAH_#{source_card}.png",__FILE__)).first
  img.x_resolution = img.y_resolution = 300
  img.composite!(cap, 75, 75, Magick::OverCompositeOp)
  if block_given?
    yield(img)
  else
    img
  end
end

#white(text, &block) ⇒ Object



25
26
27
# File 'lib/cahdmaker.rb', line 25

def white(text, &block)
  make_card(text, "White", &block)
end