Class: UrlExpander::Expanders::Basic

Inherits:
Object
  • Object
show all
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="",options={})
      @parent_klass = self
      super(shot_url,options)
    end
  end
end

end

Usage: client = UrlExpander::Client.new client.expand(“tinyurl.com/asdf”)

Instance Attribute Summary collapse

Instance Method Summary collapse

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="",options={})
  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_urlObject

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_klassObject (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

#partternObject (readonly)

Returns the value of attribute parttern.



33
34
35
# File 'lib/url_expander/expanders/basic.rb', line 33

def parttern
  @parttern
end