Class: UrlExpander::Expanders::Simurl

Inherits:
Scrape
  • Object
show all
Defined in:
lib/url_expander/expanders/scrape/simurl.rb

Overview

Expand simurl.com/ URLS Usage: UrlExpander::Client.expand(“simurl.com/fendaz”)

Defined Under Namespace

Classes: Request

Constant Summary collapse

PATTERN =
%r'(http://simurl\.com(/[\w/]+))'

Instance Attribute Summary collapse

Attributes inherited from Scrape

#long_url, #parttern

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(short_url = "", options = {}) ⇒ Simurl

Returns a new instance of Simurl.



12
13
14
15
# File 'lib/url_expander/expanders/scrape/simurl.rb', line 12

def initialize(short_url="", options={})
  @parent_klass = self.class
  super(short_url, options)
end

Instance Attribute Details

#parent_klassObject (readonly)

Returns the value of attribute parent_klass.



10
11
12
# File 'lib/url_expander/expanders/scrape/simurl.rb', line 10

def parent_klass
  @parent_klass
end

Class Method Details

.scrape_url(html) ⇒ Object

How to scarpe the url from a Qsr.li html document

Raises:



18
19
20
21
22
23
24
25
26
# File 'lib/url_expander/expanders/scrape/simurl.rb', line 18

def self.scrape_url(html)
  doc = Hpricot(html)
  str = doc.at("meta").attributes['content']
  start_slice = str.index("=") +1
  end_slice   = str.size - start_slice 
  url = str.slice(start_slice, end_slice)
  raise UrlExpander::Error.new('page not found',404) if url == "/index.php"
  url
end