From 7c7a8572163f4ab26ff2934af24458a09f8bf191 Mon Sep 17 00:00:00 2001 From: Kasper Grubbe Date: Tue, 9 Apr 2013 12:15:44 +0200 Subject: [PATCH] Adding options hash --- .ruby-version | 2 +- README.md | 14 ++++++++++++++ lib/embedda.rb | 12 +++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.ruby-version b/.ruby-version index b6a70da..ae6d5b9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -1.9.3-p385 +1.9.3-p392 diff --git a/README.md b/README.md index 39a9425..36ad36b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,20 @@ This gem adds `String#embedda` to Ruby strings. You use it like this: => "String heheh yeah" ``` +If you need only one of the parsers you can do like this: + +```ruby +[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(:filters => :youtube) +=> "String heheh yeah" +``` + +This is the default behavoir: + +```ruby +[2] pry(main)> "String heheh http://www.youtube.com/watch?v=BVtYSy83XXw yeah".embedda(:filters => [:youtube, :vimeo]) +=> "String heheh yeah" +``` + ## Links Rubygems: https://rubygems.org/gems/embedda \ No newline at end of file diff --git a/lib/embedda.rb b/lib/embedda.rb index ad2b05b..06accd4 100644 --- a/lib/embedda.rb +++ b/lib/embedda.rb @@ -1,7 +1,13 @@ class String - def embedda - compiled = youtube_replace(self) - compiled = vimeo_replace(compiled) + def embedda(options = {}) + options = {:filters => [:youtube, :vimeo]}.merge(options) + + # Make sure that filters is an array because we allow the short form of + # "hello".embedda(:filters => :youtube) instead of "hello".embedda(:filters => [:youtube]) + options[:filters] = Array(options[:filters]) + + compiled = youtube_replace(self) if options[:filters].include?(:youtube) + compiled = vimeo_replace(compiled) if options[:filters].include?(:vimeo) return compiled end