royw-imdb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -40,6 +40,8 @@ begin
40
40
  gem.files.reject! { |fn| File.basename(fn) =~ /^tt\d+\.html/}
41
41
 
42
42
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
43
+ gem.add_dependency('royw-roys_extensions','>= 0.0.2')
44
+ gem.add_dependency('royw-read_page_cache','>= 0.0.1')
43
45
  end
44
46
  rescue LoadError
45
47
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
@@ -59,3 +61,9 @@ Rake::RDocTask.new do |rdoc|
59
61
  rdoc.rdoc_files.include('README*')
60
62
  rdoc.rdoc_files.include('lib/**/*.rb')
61
63
  end
64
+
65
+ desc "stalk github until gem is published"
66
+ task :stalk do
67
+ `gemstalk royw imdb`
68
+ end
69
+
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -9,12 +9,12 @@ require 'hpricot'
9
9
  require 'chronic'
10
10
  require 'xmlsimple'
11
11
 
12
+ # royw gems on github
13
+ require 'roys_extensions'
14
+
15
+ # local files
12
16
  require 'imdb/optional_logger'
13
17
  require 'imdb/imdb_search'
14
18
  require 'imdb/imdb_movie'
15
19
  require 'imdb/imdb_profile'
16
20
  require 'imdb/imdb_image'
17
- require 'module_extensions'
18
- require 'string_extensions'
19
- require 'file_extensions'
20
- require 'object_extensions'
@@ -5,8 +5,8 @@ require 'imdb'
5
5
 
6
6
  $samples_dir = File.dirname(__FILE__) + '/samples'
7
7
 
8
- require 'cache_extensions'
9
- CacheExtensions.attach_to_read_page_classes($samples_dir)
8
+ require 'read_page_cache'
9
+ ReadPageCache.attach_to_classes($samples_dir)
10
10
 
11
11
  Spec::Runner.configure do |config|
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: royw-imdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Wright
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-20 00:00:00 -07:00
12
+ date: 2009-04-21 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: royw-roys_extensions
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: royw-read_page_cache
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.1
34
+ version:
16
35
  description:
17
36
  email: roy@wright.org
18
37
  executables: []
@@ -25,17 +44,12 @@ files:
25
44
  - History.txt
26
45
  - Rakefile
27
46
  - VERSION.yml
28
- - lib/file_extensions.rb
29
47
  - lib/imdb.rb
30
48
  - lib/imdb/imdb_image.rb
31
49
  - lib/imdb/imdb_movie.rb
32
50
  - lib/imdb/imdb_profile.rb
33
51
  - lib/imdb/imdb_search.rb
34
52
  - lib/imdb/optional_logger.rb
35
- - lib/module_extensions.rb
36
- - lib/object_extensions.rb
37
- - lib/string_extensions.rb
38
- - spec/cache_extensions.rb
39
53
  - spec/imdb_image_spec.rb
40
54
  - spec/imdb_movie_spec.rb
41
55
  - spec/imdb_profile_spec.rb
@@ -89,7 +103,6 @@ specification_version: 2
89
103
  summary: TODO
90
104
  test_files:
91
105
  - spec/imdb_movie_spec.rb
92
- - spec/cache_extensions.rb
93
106
  - spec/spec_helper.rb
94
107
  - spec/imdb_search_spec.rb
95
108
  - spec/imdb_image_spec.rb
@@ -1,18 +0,0 @@
1
- # == Synopsis
2
- # add a mkdirs method to the File class
3
- class File
4
- class << self
5
- my_extension("mkdirs") do
6
- ##
7
- # make directories including any missing in the path
8
- #
9
- # @param [String] dirspec the path to make sure exists
10
- def File.mkdirs(dirspec)
11
- unless File.exists?(dirspec)
12
- mkdirs(File.dirname(dirspec))
13
- Dir.mkdir(dirspec)
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,27 +0,0 @@
1
- ######################################################################
2
- # my extensions to Module. (taken from rake, named changed to not clash
3
- # when rake is used for this rails project.
4
- #
5
- class Module
6
- # Check for an existing method in the current class before extending. IF
7
- # the method already exists, then a warning is printed and the extension is
8
- # not added. Otherwise the block is yielded and any definitions in the
9
- # block will take effect.
10
- #
11
- # Usage:
12
- #
13
- # class String
14
- # rake_extension("xyz") do
15
- # def xyz
16
- # ...
17
- # end
18
- # end
19
- # end
20
- #
21
- def my_extension(method)
22
- unless instance_methods.include?(method.to_s) || instance_methods.include?(method.to_sym)
23
- yield
24
- end
25
- end
26
- end # module Module
27
-
@@ -1,24 +0,0 @@
1
- # == Synopsis
2
- # add a blank? method to all Objects
3
- class Object
4
- my_extension("blank?") do
5
- # return asserted if object is nil or empty
6
- def blank?
7
- result = nil?
8
- unless result
9
- if respond_to? 'empty?'
10
- if respond_to? 'strip'
11
- result = strip.empty?
12
- else
13
- if respond_to? 'compact'
14
- result = compact.empty?
15
- else
16
- result = empty?
17
- end
18
- end
19
- end
20
- end
21
- result
22
- end
23
- end
24
- end
@@ -1,40 +0,0 @@
1
- require 'cgi'
2
- require 'iconv'
3
-
4
- class String
5
- my_extension("unescape_html") do
6
- def unescape_html
7
- Iconv.conv("UTF-8", 'ISO-8859-1', CGI::unescapeHTML(self))
8
- end
9
- end
10
-
11
- # this handles unicode characters by converting each byte to "%XX"
12
- # where XX is the hex value
13
- my_extension("escape_unicode") do
14
- def escape_unicode
15
- self.each_byte.collect{|c| c.to_i > 127 ? "%#{c.to_i.to_s(16)}" : c.chr}.join('')
16
- end
17
- end
18
-
19
- my_extension("strip_tags") do
20
- def strip_tags
21
- gsub(/<\/?[^>]*>/, "")
22
- end
23
- end
24
-
25
- my_extension("ext") do
26
- # Replace the file extension with +newext+. If there is no extenson on
27
- # the string, append the new extension to the end. If the new extension
28
- # is not given, or is the empty string, remove any existing extension.
29
- #
30
- # +ext+ is a user added method for the String class.
31
- def ext(newext='')
32
- return self.dup if ['.', '..'].include? self
33
- if newext != ''
34
- newext = (newext =~ /^\./) ? newext : ("." + newext)
35
- end
36
- dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || self + newext
37
- end
38
- end
39
- end
40
-
@@ -1,53 +0,0 @@
1
-
2
- # override the classes' read_page method and replace with one
3
- # that will cache pages in spec/samples/{url}
4
-
5
- module CacheExtensions
6
- # == Synopsis
7
- # Attach the read_page and cache_file methods to the given
8
- # class (cls) and use the given directory for the cache files
9
- def self.attach_to(cls, directory='/tmp')
10
-
11
- # define the read_page(page) method on the given class: cls
12
- cls.send('define_method', "read_page") do |page|
13
- data = nil
14
- filespec = page.gsub(/^http:\//, directory).gsub(/\/$/, '.html')
15
- if File.exist?(filespec)
16
- data = open(filespec).read
17
- else
18
- data = open(page).read
19
- cache_file(page, data)
20
- end
21
- data
22
- end
23
-
24
- # define the cache_file(page, data) method on the given class: cls
25
- cls.send('define_method', "cache_file") do |page, data|
26
- begin
27
- filespec = page.gsub(/^http:\//, directory).gsub(/\/$/, '.html')
28
- unless File.exist?(filespec)
29
- puts "caching #{filespec}"
30
- File.mkdirs(File.dirname(filespec))
31
- File.open(filespec, 'w') { |f| f.puts data }
32
- end
33
- rescue Exception => eMsg
34
- puts eMsg.to_s
35
- end
36
- end
37
- end
38
-
39
- # == Synopsis
40
- # Find all classes that have a read_page instance method and
41
- # then overwrite that read_page method with one that handles
42
- # the caching. Use the given directory for the cache files.
43
- def self.attach_to_read_page_classes(directory='/tmp')
44
- ObjectSpace.each_object(Class) do |cls|
45
- if(cls.public_instance_methods(false).include?("read_page") ||
46
- cls.protected_instance_methods(false).include?("read_page") ||
47
- cls.private_instance_methods(false).include?("read_page"))
48
- CacheExtensions.attach_to(cls, directory)
49
- end
50
- end
51
- end
52
- end
53
-