Browse Source

sprues: upgrade to classy_hash 0.2.0

dev
Andy Meneely 9 years ago
parent
commit
391193812d
  1. 51
      lib/squib/sprues/sprue.rb
  2. 50
      lib/squib/sprues/sprue_schema.rb
  3. 8
      spec/sprue_spec.rb
  4. 2
      squib.gemspec

51
lib/squib/sprues/sprue.rb

@ -4,6 +4,7 @@ require_relative '../args/color_validator'
require_relative '../args/unit_conversion' require_relative '../args/unit_conversion'
require_relative 'crop_line' require_relative 'crop_line'
require_relative 'crop_line_dash' require_relative 'crop_line_dash'
require_relative 'sprue_schema'
module Squib module Squib
class Sprue class Sprue
@ -31,7 +32,7 @@ module Squib
attr_reader :dpi attr_reader :dpi
def initialize(template_hash, dpi) def initialize(template_hash, dpi)
ClassyHash.validate(template_hash, SCHEMA) ClassyHash.validate(template_hash, Sprues::SCHEMA)
@template_hash = template_hash @template_hash = template_hash
@dpi = dpi @dpi = dpi
@crop_line_default = @template_hash['crop_line'].select do |k, _| @crop_line_default = @template_hash['crop_line'].select do |k, _|
@ -132,54 +133,6 @@ module Squib
private private
# Template file schema
UNIT_REGEX = /^(\d*[.])?\d+(in|cm|mm)$/
ROTATE_REGEX = /^(\d*[.])?\d+(deg|rad)?$/
SCHEMA = {
'sheet_width' => UNIT_REGEX,
'sheet_height' => UNIT_REGEX,
'card_width' => UNIT_REGEX,
'card_height' => UNIT_REGEX,
'position_reference' => ClassyHash::G.enum(:topleft, :center),
'rotate' => [
:optional, Numeric,
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
ROTATE_REGEX
],
'crop_line' => {
'style' => [
ClassyHash::G.enum(:solid, :dotted, :dashed),
Sprues::CropLineDash::VALIDATION_REGEX
],
'width' => UNIT_REGEX,
'color' => [String, Symbol],
'overlay' => ClassyHash::G.enum(
:on_margin, :overlay_on_cards, :beneath_cards
),
'lines' => [[{
'type' => ClassyHash::G.enum(:horizontal, :vertical),
'position' => UNIT_REGEX,
'style' => [
:optional, ClassyHash::G.enum(:solid, :dotted, :dashed)
],
'width' => [:optional, UNIT_REGEX],
'color' => [:optional, String, Symbol],
'overlay_on_cards' => [:optional, TrueClass]
}]]
},
'cards' => [[{
'x' => UNIT_REGEX,
'y' => UNIT_REGEX,
# NOTE: Don't think that we should specify rotation on a per card
# basis, but just included here for now
'rotate' => [
:optional, Numeric,
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
ROTATE_REGEX
]
}]]
}.freeze
# Return path for built-in sheet templates # Return path for built-in sheet templates
def self.builtin(file) def self.builtin(file)
"#{File.dirname(__FILE__)}/../builtin/sprues/#{file}" "#{File.dirname(__FILE__)}/../builtin/sprues/#{file}"

50
lib/squib/sprues/sprue_schema.rb

@ -0,0 +1,50 @@
module Squib
module Sprues
UNIT_REGEX = /^(\d*[.])?\d+(in|cm|mm)$/
ROTATE_REGEX = /^(\d*[.])?\d+(deg|rad)?$/
SCHEMA = {
'sheet_width' => UNIT_REGEX,
'sheet_height' => UNIT_REGEX,
'card_width' => UNIT_REGEX,
'card_height' => UNIT_REGEX,
'position_reference' => ClassyHash::G.enum(:topleft, :center),
'rotate' => [
:optional, Numeric,
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
ROTATE_REGEX
],
'crop_line' => {
'style' => [
ClassyHash::G.enum(:solid, :dotted, :dashed),
Sprues::CropLineDash::VALIDATION_REGEX
],
'width' => UNIT_REGEX,
'color' => [String, Symbol],
'overlay' => ClassyHash::G.enum(
:on_margin, :overlay_on_cards, :beneath_cards
),
'lines' => [[{
'type' => ClassyHash::G.enum(:horizontal, :vertical),
'position' => UNIT_REGEX,
'style' => [
:optional, ClassyHash::G.enum(:solid, :dotted, :dashed)
],
'width' => [:optional, UNIT_REGEX],
'color' => [:optional, String, Symbol],
'overlay_on_cards' => [:optional, TrueClass]
}]]
},
'cards' => [[{
'x' => UNIT_REGEX,
'y' => UNIT_REGEX,
# NOTE: Don't think that we should specify rotation on a per card
# basis, but just included here for now
'rotate' => [
:optional, Numeric,
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
ROTATE_REGEX
]
}]]
}.freeze
end
end

8
spec/sprue_spec.rb

@ -148,7 +148,7 @@ describe Squib::Sprue do
expect do expect do
Squib::Sprue.load(sprue_file('fail_no_sheet_width.yml'), 100) Squib::Sprue.load(sprue_file('fail_no_sheet_width.yml'), 100)
end.to raise_error( end.to raise_error(
RuntimeError, ClassyHash::SchemaViolationError,
'"sheet_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' '"sheet_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
) )
end end
@ -157,7 +157,7 @@ describe Squib::Sprue do
expect do expect do
Squib::Sprue.load(sprue_file('fail_no_sheet_height.yml'), 100) Squib::Sprue.load(sprue_file('fail_no_sheet_height.yml'), 100)
end.to raise_error( end.to raise_error(
RuntimeError, ClassyHash::SchemaViolationError,
'"sheet_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' '"sheet_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
) )
end end
@ -166,7 +166,7 @@ describe Squib::Sprue do
expect do expect do
Squib::Sprue.load(sprue_file('fail_no_card_width.yml'), 100) Squib::Sprue.load(sprue_file('fail_no_card_width.yml'), 100)
end.to raise_error( end.to raise_error(
RuntimeError, ClassyHash::SchemaViolationError,
'"card_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' '"card_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
) )
end end
@ -175,7 +175,7 @@ describe Squib::Sprue do
expect do expect do
Squib::Sprue.load(sprue_file('fail_no_card_height.yml'), 100) Squib::Sprue.load(sprue_file('fail_no_card_height.yml'), 100)
end.to raise_error( end.to raise_error(
RuntimeError, ClassyHash::SchemaViolationError,
'"card_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' '"card_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
) )
end end

2
squib.gemspec

@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib'] spec.require_paths = ['lib']
spec.add_runtime_dependency 'cairo', '1.15.9' spec.add_runtime_dependency 'cairo', '1.15.9'
spec.add_runtime_dependency 'classy_hash', '0.1.5' spec.add_runtime_dependency 'classy_hash', '0.2.0'
spec.add_runtime_dependency 'gio2', '3.1.8' spec.add_runtime_dependency 'gio2', '3.1.8'
spec.add_runtime_dependency 'gobject-introspection', '3.1.8' spec.add_runtime_dependency 'gobject-introspection', '3.1.8'
spec.add_runtime_dependency 'highline', '1.7.8' spec.add_runtime_dependency 'highline', '1.7.8'

Loading…
Cancel
Save