From 1f293bcaa4069f34f05ef69ff8a7a841c7f759bb Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 30 Sep 2014 08:57:33 -0400 Subject: [PATCH] Add ability to use RegExp as an active layer name match. --- README.md | 2 ++ lib/svggvs/session.rb | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6a6d9e..378a158 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ Create a `Cardfile` in your working directory. It should look something like thi @session.configure do |c| # manipulate the data after reading from the spreadsheet # c.post_read_data = proc { |data| + # data[:active_layers] << "My Cool Layer" + # data[:active_layers] << /a regular expression/i # data[:replacements]['Superpower Text'] << '!!' # } diff --git a/lib/svggvs/session.rb b/lib/svggvs/session.rb index ecb25d1..148f082 100644 --- a/lib/svggvs/session.rb +++ b/lib/svggvs/session.rb @@ -55,6 +55,27 @@ module SVGGVS card_finished! end + class ActiveLayerMatcher < SimpleDelegator + def initialize(layers) + @layers = layers + end + + def __getobj__ + @layers + end + + def include?(name) + @layers.any? { |layer| + case layer + when Regexp + layer =~ name + else + layer == name + end + } + end + end + def data_source=(source) data_source = DataSource.new(source) @@ -68,7 +89,7 @@ module SVGGVS with_new_target do |target| target.inject! - target.active_layers = card[:active_layers] + target.active_layers = ActiveLayerMatcher.new(card[:active_layers]) target.replacements = card[:replacements] end end