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