royw-imdb 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/file_extensions.rb +12 -8
- data/lib/imdb.rb +12 -9
- data/lib/module_extensions.rb +27 -0
- data/lib/string_extensions.rb +25 -9
- metadata +2 -1
data/VERSION.yml
CHANGED
data/lib/file_extensions.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
# == Synopsis
|
2
2
|
# add a mkdirs method to the File class
|
3
3
|
class File
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
data/lib/imdb.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
1
4
|
require 'rubygems'
|
2
5
|
require 'open-uri'
|
3
6
|
require 'date'
|
4
7
|
require 'cgi'
|
5
8
|
require 'hpricot'
|
6
9
|
require 'chronic'
|
7
|
-
require 'ruby-debug'
|
8
10
|
require 'xmlsimple'
|
9
11
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
12
|
+
require 'imdb/optional_logger'
|
13
|
+
require 'imdb/imdb_search'
|
14
|
+
require 'imdb/imdb_movie'
|
15
|
+
require 'imdb/imdb_profile'
|
16
|
+
require 'imdb/imdb_image'
|
17
|
+
require 'module_extensions'
|
18
|
+
require 'string_extensions'
|
19
|
+
require 'file_extensions'
|
20
|
+
require 'object_extensions'
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
data/lib/string_extensions.rb
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
require 'iconv'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
8
9
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
my_extension("strip_tags") do
|
12
|
+
def strip_tags
|
13
|
+
gsub(/<\/?[^>]*>/, "")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
my_extension("ext") do
|
18
|
+
# Replace the file extension with +newext+. If there is no extenson on
|
19
|
+
# the string, append the new extension to the end. If the new extension
|
20
|
+
# is not given, or is the empty string, remove any existing extension.
|
21
|
+
#
|
22
|
+
# +ext+ is a user added method for the String class.
|
23
|
+
def ext(newext='')
|
24
|
+
return self.dup if ['.', '..'].include? self
|
25
|
+
if newext != ''
|
26
|
+
newext = (newext =~ /^\./) ? newext : ("." + newext)
|
27
|
+
end
|
28
|
+
dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || self + newext
|
29
|
+
end
|
12
30
|
end
|
13
|
-
|
14
31
|
end
|
15
32
|
|
16
|
-
String.send :include, ImdbStringExtensions
|
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.0.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Wright
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- lib/imdb/imdb_profile.rb
|
33
33
|
- lib/imdb/imdb_search.rb
|
34
34
|
- lib/imdb/optional_logger.rb
|
35
|
+
- lib/module_extensions.rb
|
35
36
|
- lib/object_extensions.rb
|
36
37
|
- lib/string_extensions.rb
|
37
38
|
- spec/cache_extensions.rb
|