Skip to content

Commit

Permalink
Adding options hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspergrubbe committed Apr 9, 2013
1 parent cba0f6f commit 7c7a857
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.3-p385
1.9.3-p392
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ This gem adds `String#embedda` to Ruby strings. You use it like this:
=> "String heheh <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> 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 <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> 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 <iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/BVtYSy83XXw\" frameborder=\"0\" allowfullscreen></iframe> yeah"
```

## Links

Rubygems: https://rubygems.org/gems/embedda
12 changes: 9 additions & 3 deletions lib/embedda.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7c7a857

Please sign in to comment.