13 changed files with 154 additions and 50 deletions
@ -0,0 +1,35 @@ |
|||||||
|
require_relative '../errors_warnings/warn_unexpected_params' |
||||||
|
|
||||||
|
module Squib |
||||||
|
class Deck |
||||||
|
def grid(opts = {}) |
||||||
|
DSL::Grid.new(self, __callee__).run(opts) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
module DSL |
||||||
|
class Grid |
||||||
|
include WarnUnexpectedParams |
||||||
|
attr_reader :dsl_method, :deck |
||||||
|
|
||||||
|
def initialize(deck, dsl_method) |
||||||
|
@deck = deck |
||||||
|
@dsl_method = dsl_method |
||||||
|
end |
||||||
|
|
||||||
|
def self.accepted_params |
||||||
|
%i(x y width height |
||||||
|
fill_color stroke_color stroke_width stroke_strategy dash cap |
||||||
|
range layout) |
||||||
|
end |
||||||
|
|
||||||
|
def run(opts) |
||||||
|
warn_if_unexpected opts |
||||||
|
range = Args::CardRange.new(opts[:range], deck_size: deck.size) |
||||||
|
draw = Args::Draw.new(@deck.custom_colors).extract!(opts, deck) |
||||||
|
box = Args.extract_box(opts, deck) |
||||||
|
range.each { |i| deck.cards[i].grid(box[i], draw[i]) } |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
require 'spec_helper' |
||||||
|
require 'active_support' |
||||||
|
require 'active_support/core_ext/string/inflections' |
||||||
|
|
||||||
|
def documented_options(dsl_method) |
||||||
|
rst = doc_dsl_rst dsl_method.to_s.underscore |
||||||
|
options_rst = rst[/Options.+^+(.+)^+/m] |
||||||
|
includes = options_rst.scan(/\.\. include:: \/args\/(.+)\.rst/).flatten |
||||||
|
includes.each do |key| |
||||||
|
options_rst.gsub!(".. include:: /args/#{key}.rst", doc_args_rst(key)) |
||||||
|
end |
||||||
|
opts = options_rst.lines.select { |line| line.match? /^[a-z]/ } |
||||||
|
opts.map { |o| o.strip.to_sym } |
||||||
|
end |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
require 'spec_helper' |
||||||
|
require_relative 'docs_helper' |
||||||
|
|
||||||
|
describe 'docs spec helper' do |
||||||
|
|
||||||
|
it 'gets all documented options for background' do |
||||||
|
options = documented_options(:Background) |
||||||
|
expect(options.sort).to eq(%i(color range)) |
||||||
|
end |
||||||
|
|
||||||
|
it 'gets all documented options for grid' do |
||||||
|
expected = %i(x y width height fill_color stroke_color stroke_width |
||||||
|
stroke_strategy dash cap range layout) |
||||||
|
options = documented_options(:Grid) |
||||||
|
expect(options.sort).to eq(expected.sort) |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
require_relative 'docs_helper' |
||||||
|
|
||||||
|
describe Squib::DSL do |
||||||
|
context 'methods' do |
||||||
|
|
||||||
|
Squib::DSL.constants.each do |m| |
||||||
|
it "accepted params for #{m} are in the docs" do |
||||||
|
accepted_params = Squib::DSL.const_get(m).accepted_params |
||||||
|
expect(accepted_params).to eq(documented_options(m)) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
require 'spec_helper' |
||||||
|
|
||||||
|
describe Squib::Deck do |
||||||
|
context '#background' do |
||||||
|
|
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue