-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.rb
More file actions
38 lines (32 loc) · 942 Bytes
/
helpers.rb
File metadata and controls
38 lines (32 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'nokogiri'
def is_image?(url)
url =~ /twitpic.com|yfrog.com|instagr.am|img.ly|ow.ly|.jpg|.jpeg|.gif|.png/i
end
def get_image_url(url)
case url
when /twitpic.com/i
"http://twitpic.com/show/full/#{url.split('/')[3]}"
when /yfrog.com/i
"http://yfrog.com/#{url.split('/')[3]}:medium"
when /instagr.am/i
"http://instagr.am/p/#{url.split('/')[4]}/media?size=m"
when /img.ly/i
get_imgly_url(url)
when /ow.ly/i
"http://static.ow.ly/photos/normal/#{url.split('/')[4]}.jpg"
when /.jpg|.jpeg|.gif|.png/i
url
end
end
def get_imgly_url(url)
doc = Nokogiri::HTML(open(url))
image_url = doc.search("li[@id='button-fullview']/a").first['href']
image_id = image_url.split('/')[2]
image_url = "http://s3.amazonaws.com/imgly_production/#{image_id}/medium.jpg"
end
def is_a_hug?(text)
text =~ /hug|friday/i
end
def current_page
params[:page].to_i > 0 ? params[:page].to_i : 1
end