cleanup
parent
02bf443abf
commit
750cb40267
|
|
@ -2,17 +2,17 @@ require_relative '../constants'
|
||||||
require_relative '../conf'
|
require_relative '../conf'
|
||||||
require 'ostruct'
|
require 'ostruct'
|
||||||
|
|
||||||
module Squib
|
|
||||||
# @api private
|
|
||||||
module Args
|
|
||||||
|
|
||||||
# Intended to be used a a mix-in,
|
# Intended to be used a a mix-in,
|
||||||
# For example use see Box as an example
|
# For example use see Box as an example
|
||||||
module ArgLoader
|
module Squib::Args::ArgLoader
|
||||||
|
|
||||||
|
# wrapper for compatibility
|
||||||
|
def extract!(args, deck)
|
||||||
|
load!(args, expand_by: deck.size, layout: deck.layout, dpi: deck.dpi)
|
||||||
|
end
|
||||||
|
|
||||||
# Main class invoked by the client (i.e. api/ methods)
|
# Main class invoked by the client (i.e. api/ methods)
|
||||||
def load!(args, expand_by: 1, layout: {}, dpi: 300)
|
def load!(args, expand_by: 1, layout: {}, dpi: 300)
|
||||||
Squib.logger.debug { "ARG LOADER: load! for #{self.class}, args: #{args}" }
|
|
||||||
@dpi = dpi
|
@dpi = dpi
|
||||||
args[:layout] = prep_layout_args(args[:layout], expand_by: expand_by)
|
args[:layout] = prep_layout_args(args[:layout], expand_by: expand_by)
|
||||||
expand_and_set_and_defaultify(args: args, by: expand_by, layout: layout)
|
expand_and_set_and_defaultify(args: args, by: expand_by, layout: layout)
|
||||||
|
|
@ -111,16 +111,13 @@ module Squib
|
||||||
p_str = "@#{p}"
|
p_str = "@#{p}"
|
||||||
p_val = instance_variable_get(p_str)
|
p_val = instance_variable_get(p_str)
|
||||||
if p_val.respond_to? :each
|
if p_val.respond_to? :each
|
||||||
arr = p_val.map { |x| UnitConversion.parse(x, dpi) }
|
arr = p_val.map { |x| Squib::Args::UnitConversion.parse(x, dpi) }
|
||||||
instance_variable_set p_str, arr
|
instance_variable_set p_str, arr
|
||||||
else
|
else
|
||||||
instance_variable_set p_str, UnitConversion.parse(p_val, dpi)
|
instance_variable_set p_str, Squib::Args::UnitConversion.parse(p_val, dpi)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ require_relative '../errors_warnings/warn_unexpected_params'
|
||||||
|
|
||||||
module Squib
|
module Squib
|
||||||
class Deck
|
class Deck
|
||||||
def background(opts = {}) # DSL method. See http://squib.readthedocs.io
|
def background(opts = {})
|
||||||
BackgroundDSLMethod.new(self, __callee__).run(opts)
|
DSL::Background.new(self, __callee__).run(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class BackgroundDSLMethod
|
module DSL
|
||||||
|
class Background
|
||||||
include WarnUnexpectedParams
|
include WarnUnexpectedParams
|
||||||
|
|
||||||
attr_reader :dsl_method, :deck
|
attr_reader :dsl_method, :deck
|
||||||
|
|
||||||
def initialize(deck, dsl_method)
|
def initialize(deck, dsl_method)
|
||||||
|
|
@ -26,9 +26,10 @@ module Squib
|
||||||
|
|
||||||
def run(opts)
|
def run(opts)
|
||||||
warn_if_unexpected opts
|
warn_if_unexpected opts
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: @deck.size)
|
range = Args::CardRange.new(opts[:range], deck_size: deck.size)
|
||||||
draw = Args::Draw.new(@deck.custom_colors).load!(opts, expand_by: @deck.size, layout: @deck.layout, dpi: @deck.dpi)
|
draw = Args::Draw.new(@deck.custom_colors).extract!(opts, deck)
|
||||||
range.each { |i| @deck.cards[i].background(draw.color[i]) }
|
range.each { |i| @deck.cards[i].background(draw.color[i]) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module Squib::WarnUnexpectedParams
|
||||||
def warn_if_unexpected(opts, uplevel: 5)
|
def warn_if_unexpected(opts, uplevel: 5)
|
||||||
unexpected = opts.keys - accepted_params
|
unexpected = opts.keys - accepted_params
|
||||||
unexpected.each do |key|
|
unexpected.each do |key|
|
||||||
warn "Unexpected parameter '#{key.to_s.yellow}:' to #{dsl_method.to_s.cyan}(), ignoring...",
|
warn "Unexpected parameter '#{key.to_s.yellow}:' to #{dsl_method.to_s.cyan}(). Accepted parameters: #{accepted_params}",
|
||||||
uplevel: uplevel
|
uplevel: uplevel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,10 @@ def project_template(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/../lib/squib/project_template/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/../lib/squib/project_template/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def doc(file)
|
||||||
|
"#{File.expand_path(File.dirname(__FILE__))}/../docs/#{file}"
|
||||||
|
end
|
||||||
|
|
||||||
def conf(file)
|
def conf(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/data/conf/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/data/conf/#{file}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue