Browse Source

Unit conversion on Squib::Deck.new

Contributes to #21
dev
Andy Meneely 11 years ago
parent
commit
d848178bfe
  1. 12
      lib/squib/deck.rb
  2. 6
      spec/deck_spec.rb

12
lib/squib/deck.rb

@ -6,6 +6,7 @@ require 'squib/progress'
require 'squib/input_helpers' require 'squib/input_helpers'
require 'squib/constants' require 'squib/constants'
require 'squib/layout_parser' require 'squib/layout_parser'
require 'squib/args/unit_conversion'
# The project module # The project module
# #
@ -46,8 +47,8 @@ module Squib
# text str: 'Hello, World!" # text str: 'Hello, World!"
# end # end
# #
# @param width [Integer] the width 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 # @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 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 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 config [String] the file used for global settings of this deck
@ -55,20 +56,21 @@ module Squib
# @param block [Block] the main body of the script. # @param block [Block] the main body of the script.
# @api public # @api public
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block) def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
@width=width; @height=height
@dpi = dpi @dpi = dpi
@width = Args::UnitConversion.parse width, dpi
@height = Args::UnitConversion.parse height, dpi
@font = Squib::SYSTEM_DEFAULTS[:default_font] @font = Squib::SYSTEM_DEFAULTS[:default_font]
@cards = [] @cards = []
@custom_colors = {} @custom_colors = {}
@img_dir = '.' @img_dir = '.'
@progress_bar = Squib::Progress.new(false) @progress_bar = Squib::Progress.new(false)
@text_hint = :off @text_hint = :off
cards.times{ @cards << Squib::Card.new(self, width, height) } cards.times{ @cards << Squib::Card.new(self, @width, @height) }
show_info(config, layout) show_info(config, layout)
load_config(config) load_config(config)
@layout = LayoutParser.load_layout(layout) @layout = LayoutParser.load_layout(layout)
if block_given? if block_given?
instance_eval(&block) instance_eval(&block) # here we go. wheeeee!
end end
end end

6
spec/deck_spec.rb

@ -10,6 +10,12 @@ describe Squib::Deck do
expect(d.cards.size).to eq(1) expect(d.cards.size).to eq(1)
end end
it 'can be built with unit conversion' do
d = Squib::Deck.new(width: '1in', height: '2in')
expect(d.width).to eq(300)
expect(d.height).to eq(600)
end
context 'in dealing with ranges' do context 'in dealing with ranges' do
it 'calls text on all cards by default' do it 'calls text on all cards by default' do
card1 = instance_double(Squib::Card) card1 = instance_double(Squib::Card)

Loading…
Cancel
Save