Class: Embedda

Inherits:
Object
  • Object
show all
Defined in:
lib/embedda.rb

Defined Under Namespace

Classes: UnknownFilter

Instance Method Summary collapse

Constructor Details

#initialize(string, options = {}) ⇒ Embedda

Returns a new instance of Embedda.



10
11
12
13
14
15
# File 'lib/embedda.rb', line 10

def initialize(string, options = {})
  options  = {:filters => [:youtube, :vimeo, :soundcloud]}.merge(options)
  @filters = Array(options[:filters])
  @protocol = options[:ssl] ? 'https' : 'http'
  @string  = string
end

Instance Method Details

#embedObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/embedda.rb', line 17

def embed
  return "" if @string.to_s.empty?
  @filters.each do |filter_name|
    begin
      @string = send("#{filter_name}_replace", @string)
    rescue NoMethodError
      raise UnknownFilter.new(filter_name)
    end
  end
  @string
end