damog-goodies 0.1

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/README ADDED
@@ -0,0 +1 @@
1
+ These are David Moreno's and Axiombox's Ruby goodies.
@@ -0,0 +1,5 @@
1
+ class Array
2
+ alias :has :include?
3
+ alias :has? :has
4
+ end
5
+
@@ -0,0 +1,45 @@
1
+ require "rubygems"
2
+ require "hpricot"
3
+
4
+ # for 'get'
5
+ require "#{File.join(File.expand_path(File.dirname(__FILE__)), "lwr")}"
6
+
7
+ # for 'has?'
8
+ require "#{File.join(File.expand_path(File.dirname(__FILE__)), "array")}"
9
+
10
+ module HTML
11
+ module Links
12
+ def self.find(url)
13
+ links = []
14
+ source = get(url)
15
+ Hpricot(source).search("a[@href]").each do |l|
16
+ uri = URI.parse l["href"]
17
+
18
+ links << self.absolute(url, l["href"], source) unless links.has?(l["href"])
19
+ end
20
+ links
21
+ end
22
+
23
+ def self.absolute(url, link, source = nil)
24
+ url = "http://#{url}" unless URI.parse(url).scheme =~ /^http/i
25
+
26
+ if URI.parse(link).absolute?
27
+ return link
28
+ else
29
+ source = get(url) if source.nil?
30
+
31
+ # considering base href
32
+ doc = Hpricot(source)
33
+ if not doc.at("base").nil? and not doc.at("base")["href"].nil?
34
+ base = URI.parse(doc.at("base")["href"])
35
+ else
36
+ base = URI.parse(url)
37
+ end
38
+ return base.merge(link).to_s
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+
@@ -0,0 +1,13 @@
1
+ # Little tribute to LWP
2
+ require "open-uri"
3
+
4
+ module Kernel
5
+ def get(url)
6
+ uri = URI.parse(url)
7
+ if uri.scheme
8
+ return open(url).read
9
+ else
10
+ return open("http://" + url).read
11
+ end
12
+ end
13
+ end
data/lib/goodies.rb ADDED
@@ -0,0 +1,4 @@
1
+ Dir["#{File.dirname(__FILE__)}/goodies/*"].each do |file|
2
+ puts "requiring #{file}"
3
+ require "#{file}"
4
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: damog-goodies
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - David Moreno <david@axiombox.com>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.0
23
+ version:
24
+ description: Goodies are useful classes and libraries for your everyday Ruby.
25
+ email: david@axiombox.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ files:
33
+ - README
34
+ - lib/goodies.rb
35
+ - lib/goodies/array.rb
36
+ - lib/goodies/html.rb
37
+ - lib/goodies/lwr.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/damog/goodies
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --main
43
+ - README
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Ruby's swiss army knife
65
+ test_files: []
66
+