Module: JM3::ExpandUrl
- Included in:
- String
- Defined in:
- lib/expander.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.expand(path, host) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/expander.rb', line 28 def ExpandUrl.(path, host) result = ::Net::HTTP.new(host).head(path) case result when ::Net::HTTPRedirection result['Location'] end end |
.services ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/expander.rb', line 19 def ExpandUrl.services [ { :host => "tinyurl.com", :pattern => %r'(http://tinyurl\.com(/[\w/]+))' }, { :host => "is.gd", :pattern => %r'(http://is\.gd(/[\w/]+))' }, { :host => "bit.ly", :pattern => %r'(http://bit\.ly(/[\w/]+))' }, { :host => "t.co", :pattern => %r'(http://t\.co(/[\w/]+))' }, ] end |
Instance Method Details
#expand_urls ⇒ Object
13 14 15 16 17 |
# File 'lib/expander.rb', line 13 def s = dup s. s end |
#expand_urls! ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/expander.rb', line 5 def ExpandUrl.services.each do |service| gsub!(service[:pattern]) { |match| ExpandUrl.($2, service[:host]) || $1 } end end |