lib/squib/deck.rb in squib-0.2.0 vs lib/squib/deck.rb in squib-0.3.0
- old
+ new
@@ -4,10 +4,11 @@
require 'squib/card'
require 'squib/progress'
require 'squib/input_helpers'
require 'squib/constants'
require 'squib/layout_parser'
+require 'squib/args/unit_conversion'
# The project module
#
# @api public
module Squib
@@ -44,32 +45,33 @@
# require 'squib'
# Squib::Deck.new do
# text str: 'Hello, World!"
# end
#
- # @param width [Integer] the width of each card in pixels
- # @param height [Integer] the height of each card in pixels
+ # @param width [Integer] the width of each card in pixels. Supports unit conversion (e.g. '2.5in').
+ # @param height [Integer] the height of each card in pixels. Supports unit conversion (e.g. '3.5in').
# @param cards [Integer] the number of cards in the deck
# @param dpi [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
# @param config [String] the file used for global settings of this deck
# @param layout [String, Array] load a YML file of custom layouts. Multiple files are merged sequentially, redefining collisons. See README and sample for details.
# @param block [Block] the main body of the script.
# @api public
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
- @width=width; @height=height
- @dpi = dpi
- @font = Squib::SYSTEM_DEFAULTS[:default_font]
- @cards = []
+ @dpi = dpi
+ @width = Args::UnitConversion.parse width, dpi
+ @height = Args::UnitConversion.parse height, dpi
+ @font = Squib::SYSTEM_DEFAULTS[:default_font]
+ @cards = []
@custom_colors = {}
- @img_dir = '.'
- @progress_bar = Squib::Progress.new(false)
- @text_hint = :off
- cards.times{ @cards << Squib::Card.new(self, width, height) }
+ @img_dir = '.'
+ @progress_bar = Squib::Progress.new(false)
+ @text_hint = :off
+ cards.times{ @cards << Squib::Card.new(self, @width, @height) }
show_info(config, layout)
load_config(config)
- @layout = LayoutParser.load_layout(layout)
+ @layout = LayoutParser.load_layout(layout)
if block_given?
- instance_eval(&block)
+ instance_eval(&block) # here we go. wheeeee!
end
end
# Directly accesses the array of cards in the deck
#