diff --git a/lib/squib/api/text_embed.rb b/lib/squib/api/text_embed.rb index 20e3b05..073e96c 100644 --- a/lib/squib/api/text_embed.rb +++ b/lib/squib/api/text_embed.rb @@ -37,7 +37,7 @@ module Squib # @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # @api public def svg(opts = {}) - # TODO: add input validation for key here + key = Args::EmbedKey.new.validate_key(opts[:key]) range = Args::CardRange.new(opts[:range], deck_size: @deck_size) paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout) box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) @@ -52,7 +52,7 @@ module Squib b.x, b.y = x, y card.svg(ifile[i].file, svg_args[i], b, paint[i], trans[i]) end - @rules[opts[:key]] = rule + @rules[key] = rule end # Context object for embedding a png within text @@ -69,7 +69,7 @@ module Squib # @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # @api public def png(opts = {}) - # TODO: add input validation for key here + key = Args::EmbedKey.new.validate_key(opts[:key]) range = Args::CardRange.new(opts[:range], deck_size: @deck_size) paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout) box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) @@ -83,7 +83,7 @@ module Squib b.x, b.y = x, y card.png(ifile[i].file, b, paint[i], trans[i]) end - @rules[opts[:key]] = rule + @rules[key] = rule end end diff --git a/lib/squib/args/embed_key.rb b/lib/squib/args/embed_key.rb new file mode 100644 index 0000000..347b246 --- /dev/null +++ b/lib/squib/args/embed_key.rb @@ -0,0 +1,17 @@ +require 'squib/args/arg_loader' + +module Squib + # @api private + module Args + + class EmbedKey + + # Validate the embed lookup key + def validate_key(str) + str.to_s + end + + end + + end +end diff --git a/spec/args/embed_key_spec.rb b/spec/args/embed_key_spec.rb new file mode 100644 index 0000000..6b81206 --- /dev/null +++ b/spec/args/embed_key_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' +require 'squib/args/embed_key' + +describe Squib::Args::EmbedKey do + + context '#validate_key' do + + it 'converts to string' do + expect(subject.validate_key(2.5)).to eq ('2.5') + end + + end +end