royw-dvdprofiler_collection 0.1.2 → 0.1.3
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/Rakefile +7 -0
- data/VERSION.yml +1 -1
- data/lib/dvdprofiler_collection.rb +4 -6
- data/spec/spec_helper.rb +2 -2
- metadata +23 -12
- data/lib/file_extensions.rb +0 -18
- data/lib/kernel_extensions.rb +0 -32
- data/lib/module_extensions.rb +0 -27
- data/lib/numeric_extensions.rb +0 -17
- data/lib/object_extensions.rb +0 -24
- data/lib/string_extensions.rb +0 -40
- data/spec/cache_extensions.rb +0 -53
data/Rakefile
CHANGED
@@ -11,6 +11,8 @@ begin
|
|
11
11
|
gem.authors = ["Roy Wright"]
|
12
12
|
|
13
13
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
gem.add_dependency('royw-roys_extensions','>= 0.0.2')
|
15
|
+
gem.add_dependency('royw-read_page_cache','>= 0.0.1')
|
14
16
|
|
15
17
|
gem.files.reject! do |fn|
|
16
18
|
result = false
|
@@ -54,3 +56,8 @@ Rake::RDocTask.new do |rdoc|
|
|
54
56
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
57
|
end
|
56
58
|
|
59
|
+
desc "stalk github until gem is published"
|
60
|
+
task :stalk do
|
61
|
+
`gemstalk royw dvdprofiler_collection`
|
62
|
+
end
|
63
|
+
|
data/VERSION.yml
CHANGED
@@ -7,12 +7,10 @@ require 'xmlsimple'
|
|
7
7
|
require 'ftools'
|
8
8
|
require 'mash'
|
9
9
|
|
10
|
-
|
11
|
-
require '
|
12
|
-
|
13
|
-
|
14
|
-
require 'object_extensions'
|
15
|
-
require 'string_extensions'
|
10
|
+
# royw gems on github
|
11
|
+
require 'roys_extensions'
|
12
|
+
|
13
|
+
# local files
|
16
14
|
require 'dvdprofiler_collection/optional_logger'
|
17
15
|
require 'dvdprofiler_collection/collection'
|
18
16
|
require 'dvdprofiler_collection/dvdprofiler_profile'
|
data/spec/spec_helper.rb
CHANGED
@@ -8,8 +8,8 @@ require 'dvdprofiler_collection'
|
|
8
8
|
TMPDIR = File.join(File.dirname(__FILE__), '../tmp')
|
9
9
|
SAMPLES_DIR = File.join(File.dirname(__FILE__), 'samples')
|
10
10
|
|
11
|
-
require '
|
12
|
-
|
11
|
+
require 'read_page_cache'
|
12
|
+
ReadPageCache.attach_to_classes(SAMPLES_DIR)
|
13
13
|
|
14
14
|
Spec::Runner.configure do |config|
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: royw-dvdprofiler_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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-
|
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: []
|
@@ -31,13 +50,6 @@ files:
|
|
31
50
|
- lib/dvdprofiler_collection/collection.rb
|
32
51
|
- lib/dvdprofiler_collection/dvdprofiler_profile.rb
|
33
52
|
- lib/dvdprofiler_collection/optional_logger.rb
|
34
|
-
- lib/file_extensions.rb
|
35
|
-
- lib/kernel_extensions.rb
|
36
|
-
- lib/module_extensions.rb
|
37
|
-
- lib/numeric_extensions.rb
|
38
|
-
- lib/object_extensions.rb
|
39
|
-
- lib/string_extensions.rb
|
40
|
-
- spec/cache_extensions.rb
|
41
53
|
- spec/collection_spec.rb
|
42
54
|
- spec/dvdprofiler_profile_spec.rb
|
43
55
|
- spec/samples/Collection.xml
|
@@ -69,7 +81,6 @@ signing_key:
|
|
69
81
|
specification_version: 2
|
70
82
|
summary: TODO
|
71
83
|
test_files:
|
72
|
-
- spec/cache_extensions.rb
|
73
84
|
- spec/collection_spec.rb
|
74
85
|
- spec/spec_helper.rb
|
75
86
|
- spec/dvdprofiler_profile_spec.rb
|
data/lib/file_extensions.rb
DELETED
@@ -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
|
data/lib/kernel_extensions.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# # == Synopsis
|
2
|
-
# # add a mkdirs method to the File class
|
3
|
-
# class File
|
4
|
-
# ##
|
5
|
-
# # make directories including any missing in the path
|
6
|
-
# #
|
7
|
-
# # @param [String] dirspec the path to make sure exists
|
8
|
-
# def File.mkdirs(dirspec)
|
9
|
-
# unless File.exists?(dirspec)
|
10
|
-
# mkdirs(File.dirname(dirspec))
|
11
|
-
# Dir.mkdir(dirspec)
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
|
16
|
-
# == Synopsis
|
17
|
-
# add a timer method to the Kernel
|
18
|
-
module Kernel
|
19
|
-
|
20
|
-
my_extension("timer") do
|
21
|
-
# == Synopsis
|
22
|
-
# a simple elapse time for the give block
|
23
|
-
# == Usage
|
24
|
-
# elapse_seconds = timer {...}
|
25
|
-
def timer
|
26
|
-
start_time = Time.now
|
27
|
-
yield
|
28
|
-
Time.now - start_time
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
data/lib/module_extensions.rb
DELETED
@@ -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
|
-
|
data/lib/numeric_extensions.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# == Synopsis
|
2
|
-
# add an elapse_time_s method to Numeric
|
3
|
-
class Numeric
|
4
|
-
my_extension("elapsed_time_s") do
|
5
|
-
# return String formated as "HH:MM:SS"
|
6
|
-
def elapsed_time_s
|
7
|
-
seconds = self
|
8
|
-
hours = minutes = 0
|
9
|
-
hours = seconds.div 3600
|
10
|
-
seconds = seconds - (hours * 3600)
|
11
|
-
minutes = seconds.div 60
|
12
|
-
seconds = seconds - (minutes * 60)
|
13
|
-
sprintf("%2.2d:%2.2d:%2.2d", hours, minutes, seconds)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
data/lib/object_extensions.rb
DELETED
@@ -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
|
data/lib/string_extensions.rb
DELETED
@@ -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
|
-
|
data/spec/cache_extensions.rb
DELETED
@@ -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
|
-
|