Class: UrlExpander::Expanders::Basic
- Inherits:
-
Object
- Object
- UrlExpander::Expanders::Basic
- Defined in:
- lib/url_expander/expanders/basic.rb
Overview
This is the basic class for all simple Net::HTTPMovedPermanently Each subclass must define a url Pattern and a Reqest class for httpartty. Ex: module UrlExpander
module Expanders
class Tinyurl < UrlExpander::Expanders::Basic
class Request
include HTTParty
base_uri 'http://tinyurl.com'
end
PATTERN = %r'(http://tinyurl\.com(/[\w/]+))'
attr_reader :parent_klass
def initialize(short_url="",={})
@parent_klass = self.class
super(shot_url,)
end
end
end
end
Usage: client = UrlExpander::Client.new client.expand(“tinyurl.com/asdf”)
Direct Known Subclasses
Adjix, Digbig, Doiop, Easyurljp, Justas, Moourl, Notlong, Nutshellurl, Owly, Shrtst, Snipurl, Tco, Tighturl, Tinycc, Tinyurl, Twurlnl, Urlie, Youtube
Instance Attribute Summary collapse
-
#long_url ⇒ Object
Returns the value of attribute long_url.
-
#parent_klass ⇒ Object
readonly
Returns the value of attribute parent_klass.
-
#parttern ⇒ Object
readonly
Returns the value of attribute parttern.
Instance Method Summary collapse
-
#initialize(short_url = "", options = {}) ⇒ Basic
constructor
A new instance of Basic.
Constructor Details
#initialize(short_url = "", options = {}) ⇒ Basic
Returns a new instance of Basic.
36 37 38 39 40 41 42 |
# File 'lib/url_expander/expanders/basic.rb', line 36 def initialize(short_url="",={}) if short_url.match(parent_klass.class::PATTERN) @long_url = parent_klass.fetch_url($2) else raise 'invalid pattern' end end |
Instance Attribute Details
#long_url ⇒ Object
Returns the value of attribute long_url.
32 33 34 |
# File 'lib/url_expander/expanders/basic.rb', line 32 def long_url @long_url end |
#parent_klass ⇒ Object (readonly)
Returns the value of attribute parent_klass.
33 34 35 |
# File 'lib/url_expander/expanders/basic.rb', line 33 def parent_klass @parent_klass end |
#parttern ⇒ Object (readonly)
Returns the value of attribute parttern.
33 34 35 |
# File 'lib/url_expander/expanders/basic.rb', line 33 def parttern @parttern end |