cinch-toolbox 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cinch-toolbox.rb CHANGED
@@ -72,5 +72,27 @@ module Cinch
72
72
  short.base_url = 'http://is.gd/'
73
73
  return short
74
74
  end
75
+
76
+ def Toolbox.get_page_title(url)
77
+ # Make sure the URL is legit
78
+ url = URI::extract(url, ["http", "https"]).first
79
+
80
+ # If the link is to an image, extract the filename.
81
+ if url.match(/\.jpg|jpeg|gif|png$/)
82
+ # unless it's from reddit, then change the url to the gallery to get the image's caption.
83
+ if url.match(/https?:\/\/i\.imgur\.com.+\/([A-Za-z0-9]+)\.(jpg|jpeg|png|gif)/)
84
+ imgur_id = url.match(/https?:\/\/i\.imgur\.com.+\/([A-Za-z0-9]+)\.(jpg|jpeg|png|gif)/)[1]
85
+ url = "http://imgur.com/#{imgur_id}"
86
+ else
87
+ site = url.match(/\.([^\.]+\.[^\/]+)/)
88
+ return site.nil? ? "Image [#{url}]!!!" : "Image from #{site[1]}"
89
+ end
90
+ end
91
+
92
+ # Grab the element, return nothing if the site doesn't have a title.
93
+ debug "URL: #{url}"
94
+ page = Nokogiri::HTML(open(url)).css('title')
95
+ return page.first.content.strip.gsub(/\s+/, ' ') unless page.empty?
96
+ end
75
97
  end
76
98
  end
@@ -1,5 +1,5 @@
1
1
  module Cinch
2
2
  module Toolbox
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
12
+ date: 2013-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri