lib/muri/base.rb in muri-0.0.1 vs lib/muri/base.rb in muri-0.0.2
- old
+ new
@@ -1,11 +1,11 @@
require 'uri'
-class MURI
- class NoTransformer < StandardError; end
+class Muri
+ class NoParser < StandardError; end
PARSERS = { }
-
+
include Filter::Youtube
include Filter::Flickr
include Filter::Vimeo
def self.parse(url)
@@ -22,15 +22,19 @@
end
def to_s
@info.to_s
end
-
+
+ def parsed?
+ @info[:media_id].nil? ? false : true
+ end
+
# Taken from uri/generic.rb
@@to_s = Kernel.instance_method(:to_s)
def inspect
- @@to_s.bind(self).call.sub!(/>\z/) {" #{self}>"}
+ @@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self.original_url}>"}
end
def parsers
PARSERS.keys
end
@@ -46,24 +50,20 @@
if parse_function = PARSERS[@url.host]
@info[:uri] = @url
@info[:original_url] = raw_url
send(parse_function)
else
- raise NoTransformer.new("No Transformer found for URL")
+ raise NoParser.new("No Transformer found for URL")
end
#rescue => e
#raise "failed #{e}"
end
-
- def field_value(field_name)
- if @info[field_name.to_sym] != nil
- @info[field_name.to_sym]
- else
- nil
- end
- end
def method_missing(func, args = nil)
- field_value(func)
+ if @info[func.to_sym] != nil
+ @info[func.to_sym]
+ else
+ nil #super(func,args)
+ end
end
end