class Squib::Deck

The main interface to Squib. Provides a front-end porcelain whereas the Card class interacts with the graphics plumbing.

@api public

Some helper methods specifically for samples @api private

Attributes

cards[R]

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck @api private

height[R]

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck @api private

progress_bar[R]

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck @api private

width[R]

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck @api private

Public Instance Methods

background(opts = {}) click to toggle source
# File lib/squib/dsl/background.rb, line 5
def background(opts = {})
  DSL::Background.new(self, __callee__).run(opts)
end
build(grp = :all, &block) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/groups.rb, line 23
def build grp = :all, &block
  raise 'Please provide a block' unless block_given?
  block.yield if build_groups.include? grp
end
build_groups() click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/groups.rb, line 41
def build_groups
  @build_groups ||= Set.new.add(:all)
end
cells(n) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/units.rb, line 32
def cells(n)
  n.to_f * @cell_px
end
circle(opts = {}) click to toggle source
# File lib/squib/dsl/circle.rb, line 8
def circle(opts = {})
  DSL::Circle.new(self, __callee__).run(opts)
end
cm(n) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/units.rb, line 17
def cm(n)
  @dpi * Squib::INCHES_IN_CM * n.to_f
end
csv(opts = {}, &block) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/csv.rb, line 15
def csv(opts = {}, &block)
  DSL::Csv.new(__callee__).run(opts, &block)
end
curve(opts = {}) click to toggle source
# File lib/squib/dsl/curve.rb, line 5
def curve(opts = {})
  DSL::Curve.new(self, __callee__).run(opts)
end
cut_zone(opts = {}) click to toggle source
# File lib/squib/dsl/cut_zone.rb, line 5
def cut_zone(opts = {})
  DSL::CutZone.new(self, __callee__).run(opts)
end
deg(n) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/units.rb, line 27
def deg(n)
  n.to_f * (Math::PI / 180.0)
end
disable_build(grp) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/groups.rb, line 35
def disable_build grp
  build_groups # make sure it's initialized
  @build_groups.delete grp
end
draw_graph_paper(width, height) click to toggle source

Draw graph paper for samples

# File lib/squib/sample_helpers.rb, line 9
def draw_graph_paper(width, height)
  background color: 'white'
  grid width: 50,  height: 50,  stroke_color: '#659ae9', stroke_width: 1.5
  grid width: 200, height: 200, stroke_color: '#659ae9', stroke_width: 3, x: 50, y: 50
  (50..height).step(200) do |y|
    text str: "y=#{y}", x: 3, y: y - 18, font: 'Open Sans, Sans 10'
  end
end
ellipse(opts = {}) click to toggle source
# File lib/squib/dsl/ellipse.rb, line 5
def ellipse(opts = {})
  DSL::Ellipse.new(self, __callee__).run(opts)
end
enable_build(grp) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/groups.rb, line 29
def enable_build grp
  build_groups # make sure it's initialized
  @build_groups << grp
end
enable_groups_from_env!() click to toggle source

Not a DSL method, but initialized from Deck.new

# File lib/squib/dsl/groups.rb, line 46
def enable_groups_from_env!
  return if ENV['SQUIB_BUILD'].nil?
  ENV['SQUIB_BUILD'].split(',').each do |grp|
    enable_build grp.strip.to_sym
  end
end
grid(opts = {}) click to toggle source
# File lib/squib/dsl/grid.rb, line 5
def grid(opts = {})
  DSL::Grid.new(self, __callee__).run(opts)
end
hand(opts = {}) click to toggle source
# File lib/squib/dsl/hand.rb, line 9
def hand(opts = {})
  DSL::Hand.new(self, __callee__).run(opts)
end
hint(text: :off) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/api/settings.rb, line 5
def hint(text: :off)
  conf.text_hint = text
end
inches(n) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/units.rb, line 7
def inches(n)
  @dpi * n.to_f
end
line(opts = {}) click to toggle source
# File lib/squib/dsl/line.rb, line 5
def line(opts = {})
  DSL::Line.new(self, __callee__).run(opts)
end
mm(n) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/units.rb, line 22
def mm(n)
  @dpi * Squib::INCHES_IN_CM * n.to_f / 10.0
end
png(opts = {}) click to toggle source
# File lib/squib/dsl/png.rb, line 10
def png(opts = {})
  DSL::PNG.new(self, __callee__).run(opts)
end
points(n) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/units.rb, line 12
def points(n)
  @dpi / Squib::POINTS_PER_IN * n.to_f
end
polygon(opts = {}) click to toggle source
# File lib/squib/dsl/polygon.rb, line 5
def polygon(opts = {})
  DSL::Polygon.new(self, __callee__).run(opts)
end
rect(opts = {}) click to toggle source
# File lib/squib/dsl/rect.rb, line 5
def rect(opts = {})
  DSL::Rect.new(self, __callee__).run(opts)
end
render_hand(range, sheet, hand) click to toggle source

Draw cards in a fan. @api private

# File lib/squib/graphics/hand.rb, line 8
def render_hand(range, sheet, hand)
  cards       = range.collect { |i| @cards[i] }
  center_x    = width / 2.0
  center_y    = hand.radius + height
  out_size    = 3.0 * center_y
  angle_delta = (hand.angle_range.last - hand.angle_range.first) / cards.size
  cxt = Cairo::Context.new(Cairo::RecordingSurface.new(0, 0, out_size, out_size))
  cxt.translate(out_size / 2.0, out_size / 2.0)
  cxt.rotate(hand.angle_range.first)
  cxt.translate(-width, -width)
  cards.each_with_index do |card, i|
    cxt.translate(center_x, center_y)
    cxt.rotate(angle_delta)
    cxt.translate(-center_x, -center_y)
    card.use_cairo do |card_cxt|
      cxt.rounded_rectangle(sheet.trim, sheet.trim,
                            width - (2 * sheet.trim), height - (2 * sheet.trim),
                            sheet.trim_radius, sheet.trim_radius)
      cxt.clip
      cxt.set_source(card_cxt.target)
      cxt.paint
      cxt.reset_clip
    end
  end
  x, y, w, h = cxt.target.ink_extents # I love Ruby assignment ;)
  png_cxt = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(Cairo::ImageSurface.new(w + 2 * sheet.margin, h + 2 * sheet.margin)))
  png_cxt.set_source_squibcolor(sheet.fill_color)
  png_cxt.paint
  png_cxt.translate(-x + sheet.margin, -y + sheet.margin)
  png_cxt.set_source(cxt.target)
  png_cxt.paint
  png_cxt.target.write_to_png sheet.full_filename
end
safe_zone(opts = {}) click to toggle source
# File lib/squib/dsl/safe_zone.rb, line 5
def safe_zone(opts = {})
  DSL::SafeZone.new(self, __callee__).run(opts)
end
sample(str) { |sample_x, sample_y| ... } click to toggle source

Define a set of samples on some graph paper

# File lib/squib/sample_helpers.rb, line 19
def sample(str)
  @sample_x ||= 100
  @sample_y ||= 100
  rect x: 460, y: @sample_y - 40, width: 600,
       height: 180, fill_color: '#FFD655', stroke_color: 'black', radius: 15
  text str: str, x: 460, y: @sample_y - 40,
       width: 540, height: 180,
       valign: 'middle', align: 'center',
       font: 'Times New Roman,Serif 8'
  yield @sample_x, @sample_y
  @sample_y += 200
end
save(opts = {}) click to toggle source
# File lib/squib/dsl/save.rb, line 8
def save(opts = {})
  fmts = Array(opts[:format])
  warn 'Must specify format :png and/or :pdf' if fmts.empty?
  opts.delete :format # not needed anymore
  save_png(opts) if fmts.include? :png
  save_pdf(opts) if fmts.include? :pdf
  uns = fmts - [:pdf, :png ]
  unless uns.empty?
    warn "Unsupported format(s) #{uns} to #{'save'.cyan}()", uplevel: 1
  end
  self
end
save_pdf(opts = {}) click to toggle source
# File lib/squib/dsl/save_pdf.rb, line 8
def save_pdf(opts = {})
  DSL::SavePDF.new(self, __callee__).run(opts)
end
save_png(opts = {}) click to toggle source
# File lib/squib/dsl/save_png.rb, line 8
def save_png(opts = {})
  DSL::SavePNG.new(self, __callee__).run(opts)
end
save_sheet(opts = {}) click to toggle source
# File lib/squib/dsl/save_sheet.rb, line 13
def save_sheet(opts = {})
  DSL::SaveSheet.new(self, __callee__).run(opts)
end
set(opts = {}) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/api/settings.rb, line 10
def set(opts = {})
  raise 'DEPRECATED: As of v0.7 img_dir is no longer supported in "set". Use config.yml instead.' if opts.key? :img_dir
  @font = (opts[:font] == :default) ? Squib::DEFAULT_FONT : opts[:font]
end
showcase(opts = {}) click to toggle source
# File lib/squib/dsl/showcase.rb, line 8
def showcase(opts = {})
  DSL::Showcase.new(self, __callee__).run(opts)
end
star(opts = {}) click to toggle source
# File lib/squib/dsl/star.rb, line 5
def star(opts = {})
  DSL::Star.new(self, __callee__).run(opts)
end
svg(opts = {}) click to toggle source
# File lib/squib/dsl/svg.rb, line 11
def svg(opts = {})
  DSL::SVG.new(self, __callee__).run(opts)
end
text(opts = {}) { |embed| ... } click to toggle source
# File lib/squib/dsl/text.rb, line 11
def text(opts = {})
  embed = TextEmbed.new self, __callee__
  yield(embed) if block_given? # store the opts for later use
  DSL::Text.new(self, __callee__, embed).run(opts)
end
triangle(opts = {}) click to toggle source
# File lib/squib/dsl/triangle.rb, line 5
def triangle(opts = {})
  DSL::Triangle.new(self, __callee__).run(opts)
end
use_layout(file: 'layout.yml') click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/api/settings.rb, line 16
def use_layout(file: 'layout.yml')
  @layout = LayoutParser.new(@dpi).load_layout(file, @layout)
end
xlsx(opts = {}, &block) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/xlsx.rb, line 14
def xlsx(opts = {}, &block)
  DSL::Xlsx.new(__callee__).run(opts, &block)
end
yaml(opts = {}, &block) click to toggle source

DSL method. See squib.readthedocs.io

# File lib/squib/dsl/yaml.rb, line 14
def yaml(opts = {}, &block)
  DSL::Yaml.new(__callee__).run(opts, &block)
end