Class: Squib::TextEmbed

Inherits:
Object
  • Object
show all
Defined in:
lib/squib/api/text_embed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deck_size, custom_colors, layout, dpi, img_dir) ⇒ TextEmbed

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:


17
18
19
20
21
22
23
24
# File 'lib/squib/api/text_embed.rb', line 17

def initialize(deck_size, custom_colors, layout, dpi, img_dir)
  @deck_size     = deck_size
  @custom_colors = custom_colors
  @layout        = layout
  @dpi           = dpi
  @img_dir       = img_dir
  @rules = {} # store an array of options for later usage
end

Instance Attribute Details

#rulesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:


13
14
15
# File 'lib/squib/api/text_embed.rb', line 13

def rules
  @rules
end

Instance Method Details

#png(opts = {}) ⇒ Object

DSL method. See squib.readthedocs.io


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/squib/api/text_embed.rb', line 50

def png(opts = {})
  key   = Args::EmbedKey.new.validate_key(opts[:key])
  range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
  paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
  box   = Args::Box.new(self, { width: :native, height: :native }).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  adjust = Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  rule  = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }
  rule[:draw] = Proc.new do |card, x, y|
    i = card.index
    b = box[i]
    b.x, b.y = x, y
    Dir.chdir(@img_dir) do
      card.png(ifile[i].file, b, paint[i], trans[i])
    end
  end
  @rules[key] = rule
end

#svg(opts = {}) ⇒ Object

DSL method. See squib.readthedocs.io


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/squib/api/text_embed.rb', line 27

def svg(opts = {})
  key   = Args::EmbedKey.new.validate_key(opts[:key])
  range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
  paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
  box   = Args::Box.new(self, { width: :native, height: :native }).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  adjust = Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  svg_args = Args::SvgSpecial.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  rule = { type: :svg, file: ifile, box: box, paint: paint, trans: trans,
           adjust: adjust, svg_args: svg_args }
  rule[:draw] = Proc.new do |card, x, y|
    i = card.index
    b = box[i]
    b.x, b.y = x, y
    Dir.chdir(@img_dir) do
      card.svg(ifile[i].file, svg_args[i], b, paint[i], trans[i])
    end
  end
  @rules[key] = rule
end