qualitysmith_extensions 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/qualitysmith_extensions/array/average.rb +2 -0
- data/lib/qualitysmith_extensions/array/expand_ranges.rb +2 -0
- data/lib/qualitysmith_extensions/array/group_by.rb +3 -1
- data/lib/qualitysmith_extensions/array/sequence.rb +2 -0
- data/lib/qualitysmith_extensions/array/shell_escape.rb +2 -0
- data/lib/qualitysmith_extensions/array/to_a_recursive.rb +2 -0
- data/lib/qualitysmith_extensions/array/to_query_string.rb +2 -0
- data/lib/qualitysmith_extensions/date/deprecated.rb +2 -0
- data/lib/qualitysmith_extensions/date/iso8601.rb +2 -0
- data/lib/qualitysmith_extensions/date/month_ranges.rb +2 -0
- data/lib/qualitysmith_extensions/enumerable/enum.rb +14 -17
- data/lib/qualitysmith_extensions/file/exact_match_regexp.rb +2 -0
- data/lib/qualitysmith_extensions/file_test/binary_file.rb +2 -0
- data/lib/qualitysmith_extensions/global_variable_set.rb +2 -0
- data/lib/qualitysmith_extensions/hash/to_date.rb +2 -0
- data/lib/qualitysmith_extensions/hash/to_query_string.rb +2 -0
- data/lib/qualitysmith_extensions/kernel/backtrace.rb +2 -0
- data/lib/qualitysmith_extensions/kernel/capture_output.rb +2 -0
- data/lib/qualitysmith_extensions/kernel/die.rb +5 -0
- data/lib/qualitysmith_extensions/{filter_output.rb → kernel/filter_output.rb} +3 -2
- data/lib/qualitysmith_extensions/kernel/require_all.rb +2 -0
- data/lib/qualitysmith_extensions/kernel/require_once.rb +2 -0
- data/lib/qualitysmith_extensions/{simulate_input.rb → kernel/simulate_input.rb} +2 -1
- data/lib/qualitysmith_extensions/month.rb +2 -0
- data/lib/qualitysmith_extensions/object/singleton.rb +40 -27
- data/lib/qualitysmith_extensions/string/digits_only.rb +2 -0
- data/lib/qualitysmith_extensions/string/md5.rb +2 -0
- data/lib/qualitysmith_extensions/string/shell_escape.rb +2 -0
- data/lib/qualitysmith_extensions/string/to_underscored_label.rb +2 -0
- data/lib/qualitysmith_extensions/test/assert_changed.rb +2 -0
- data/lib/qualitysmith_extensions/test/assert_exception.rb +2 -0
- data/lib/qualitysmith_extensions/test/assert_includes.rb +2 -0
- data/lib/qualitysmith_extensions/test/assert_user_error.rb +2 -0
- data/lib/qualitysmith_extensions/time/deprecated.rb +2 -0
- metadata +4 -4
@@ -1,9 +1,11 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Yes.
|
5
6
|
# Wait, so Facets has mode (http://facets.rubyforge.org/src/doc/rdoc/core/classes/Enumerable.html#M001253) but it doesn't have mean/average?
|
6
7
|
# Whether or not this Array#average is included, Facets ought to have an Enumerable#mean/average similar to mode that uses each iterator rather than Array#size. (Still might want to keep this version if it's more efficient for Arrays?)
|
8
|
+
#++
|
7
9
|
|
8
10
|
class Array
|
9
11
|
# Calculates the arithmetic average (mean) of the elements in the array as a <tt>Float</tt>.
|
@@ -1,9 +1,11 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Yes
|
5
6
|
# Developer notes:
|
6
7
|
# * Name is too general? Name it something to do with 'tables'?
|
8
|
+
#++
|
7
9
|
|
8
10
|
require 'rubygems'
|
9
11
|
require_gem 'facets'
|
@@ -39,7 +41,7 @@ class Array
|
|
39
41
|
"a"=>[['a', 1], ['a', 2]],
|
40
42
|
"b"=>[['b', 3], ['b', 4]]
|
41
43
|
|
42
|
-
Notes
|
44
|
+
*Notes*:
|
43
45
|
* <tt>self</tt> must be in the shape of a "table" (a non-sparse, rectangular, two-dimensional array).
|
44
46
|
* This is different from the GROUP BY in SQL in that it doesn't apply an aggregate (like sum or average) to each group -- it just returns each group unmodified.
|
45
47
|
|
@@ -1,7 +1,9 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: No!
|
6
|
+
#++
|
5
7
|
|
6
8
|
# Depends on some niceties from ActiveSupport (which really should be in core Ruby but aren't)...
|
7
9
|
require "rubygems"
|
@@ -1,7 +1,9 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Not sure.
|
6
|
+
#++
|
5
7
|
|
6
8
|
# Depends on some niceties from ActiveSupport (which really should be in core Ruby but aren't)... Date.new(a, b, c)
|
7
9
|
require "rubygems"
|
@@ -1,29 +1,32 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Yes!
|
6
|
+
#++
|
5
7
|
|
6
8
|
require 'enumerator'
|
7
9
|
module Enumerable
|
8
10
|
|
9
11
|
# The core Enumerable module provides the following enumerator methods;
|
10
|
-
# * enum_cons()
|
11
|
-
# * enum_slice()
|
12
|
-
# * enum_with_index()
|
13
|
-
# but for some reason they didn't provide a generic enum() method for the cases they didn't think of!
|
12
|
+
# * <tt>enum_cons()</tt>
|
13
|
+
# * <tt>enum_slice()</tt>
|
14
|
+
# * <tt>enum_with_index()</tt>
|
15
|
+
# but for some reason they didn't provide a generic <tt>enum()</tt> method for the cases they didn't think of!
|
14
16
|
#
|
15
|
-
# +enum+ lets you turn *any* iterator into a general-purpose Enumerator
|
16
|
-
# "A class which provides a method
|
17
|
+
# +enum+ lets you turn *any* iterator into a general-purpose <tt>Enumerator</tt>, which, according to the RDocs, is
|
18
|
+
# "A class which provides a method `<tt>each</tt>' to be used as an <tt>Enumerable</tt> object."
|
17
19
|
#
|
18
|
-
# This lets you turn any 'each'-type iterator (each_byte
|
20
|
+
# This lets you turn any '<tt>each'-type</tt> iterator (<tt>each_byte</tt>, <tt>each_line</tt>, ...) into a
|
21
|
+
# '<tt>map</tt>'-type iterator (one that returns a collection), or into an array, etc.
|
19
22
|
#
|
20
|
-
# So if an object responds to
|
23
|
+
# So if an object responds to <tt>:each_line</tt> but not to <tt>:map_lines</tt> or <tt>:lines</tt>, you could just do:
|
21
24
|
# object.enum(:each_line).map { block }
|
22
|
-
# object.enum(:each_line).to_a
|
23
25
|
# object.enum(:each_line).min
|
24
26
|
# object.enum(:each_line).grep /pattern/
|
27
|
+
# lines = object.enum(:each_line).to_a
|
25
28
|
#
|
26
|
-
# If no iterator is specified,
|
29
|
+
# If no iterator is specified, <tt>:each</tt> is assumed:
|
27
30
|
# object.enum.map { block }
|
28
31
|
#
|
29
32
|
# More examples:
|
@@ -36,13 +39,7 @@ module Enumerable
|
|
36
39
|
def enum(iterator = :each)
|
37
40
|
Enumerable::Enumerator.new(self, iterator)
|
38
41
|
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Lets you add the methods available to Enumerables to any object that responds to :each (or any other iterator).
|
42
|
-
# +enum+ returns a general-purpose Enumerator, which, according to the RDocs, is "A class which provides a method `each' to be used as an Enumerable object."
|
43
|
-
#
|
44
|
-
# This lets you use 'map'-type iterator, for example, on an object that only provides an 'each'-type iterator.
|
45
|
-
# So if an object only responds to :each, but you want to send it :map, you could just do:
|
42
|
+
|
46
43
|
end
|
47
44
|
|
48
45
|
# _____ _
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Lloyd Zusman, Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2002-2007 Lloyd Zusman
|
3
4
|
# License:: Ruby License
|
@@ -5,6 +6,7 @@
|
|
5
6
|
# * 2002-10-05: Based on code posted by Lloyd Zusman on ruby-talk on 2002-10-05 (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/52548)
|
6
7
|
# * 2007-03-15: Cleaned up a bit and wrote tests.
|
7
8
|
# Submit to Facets?:: Yes
|
9
|
+
#++
|
8
10
|
|
9
11
|
module FileTest
|
10
12
|
|
@@ -1,7 +1,9 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: No, too ugly and unreliable.
|
6
|
+
#++
|
5
7
|
|
6
8
|
module Kernel
|
7
9
|
# Gets the global variable +var+, which can either be a symbol or an actual global variable (use +:match_object+).
|
@@ -1,7 +1,9 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Yes. Unless it is deemed not generally reusable enough. Also, only if we can get a Date.new(y,m,d) added to Facets.
|
6
|
+
#++
|
5
7
|
|
6
8
|
require "rubygems"
|
7
9
|
require "active_support"
|
@@ -1,7 +1,9 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Not sure. This might not be necessary if caller() actually works reliably.
|
6
|
+
#++
|
5
7
|
|
6
8
|
require "rubygems"
|
7
9
|
require "facet/string/lines"
|
@@ -1,7 +1,9 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Yes
|
6
|
+
#++
|
5
7
|
|
6
8
|
module Kernel
|
7
9
|
def die(message)
|
@@ -17,7 +19,10 @@ end
|
|
17
19
|
# |_|\___||___/\__|
|
18
20
|
#
|
19
21
|
=begin test
|
22
|
+
require 'rubygems'
|
20
23
|
require 'qualitysmith_extensions/kernel/capture_output'
|
24
|
+
#require 'facets/core/kernel/require_local'
|
25
|
+
#require_local './capture_output'
|
21
26
|
|
22
27
|
class TheTest < Test::Unit::TestCase
|
23
28
|
|
@@ -1,9 +1,10 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Yes.
|
5
6
|
# Developer notes:
|
6
|
-
|
7
|
+
#++
|
7
8
|
|
8
9
|
require 'stringio'
|
9
10
|
|
@@ -46,7 +47,7 @@ end
|
|
46
47
|
=begin test
|
47
48
|
require 'test/unit'
|
48
49
|
|
49
|
-
# Not sure whether it's better to duplicate for increased readability or metaprogram for decreased duplication...
|
50
|
+
# Not sure whether it's better to duplicate for increased readability here or metaprogram for decreased duplication...
|
50
51
|
|
51
52
|
# Duplicate for increased readability:
|
52
53
|
def noisy_command
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
@@ -14,51 +15,55 @@
|
|
14
15
|
# * extend_call
|
15
16
|
# * create_and_send
|
16
17
|
# * create_and_call
|
18
|
+
#++
|
17
19
|
|
18
20
|
class Object
|
19
21
|
|
20
22
|
# Creates a singleton method and then calls it.
|
21
23
|
#
|
22
|
-
# More specificaly, it
|
24
|
+
# More specificaly, it <tt>extend</tt>s +self+ with the methods from +moduule+ and then sends the supplied +message+ and +args+ (if any).
|
23
25
|
#
|
24
26
|
# Advantages:
|
25
27
|
# * Keeps things object-oriented. Better than having global/class methods.
|
26
|
-
#
|
27
|
-
#
|
28
|
+
# * (<tt>"whatever".ss(MyColorizer, :colorize).ss(SomeOtherClass, :another_class_method)</tt> instead of
|
29
|
+
# * <tt>SomeOtherClass::another_class_method(MyColorizer::colorize("whatever"))</tt>)
|
30
|
+
# * Method calls are _listed_ in the order in which they are _called_.
|
28
31
|
# * Still lets you keep your methods in a namespace.
|
29
32
|
# * Doesn't clutter up the base classes with methods that are only useful within a very small context. The methods are only added to the objects you specify. So you can "use" the base class <b>without cluttering up _all_ instances of the class with your methods</b>.
|
30
33
|
# * Useful for cases where creating a subclass wouldn't help because the methods you are calling would still return instances of the base class.
|
31
34
|
#
|
32
35
|
# Disadvantages:
|
33
36
|
# * You have to have/create a *module* for the functions you want to use.
|
34
|
-
#
|
35
|
-
#
|
37
|
+
# * Can't just call .sigleton_send(self, :some_method) if you want to use +some_method+ that's defined in +self+.
|
38
|
+
# * So what do we call the module containing the "singleton method"? String::MyColorizer? MyColorizer::String? MyStringColorizer?
|
36
39
|
#
|
37
40
|
# Examples:
|
38
|
-
#
|
41
|
+
# "whatever".ss(MyColorizer, :colorize, :blue)
|
39
42
|
#
|
40
|
-
def
|
43
|
+
def singleton_send(moduule, message, *args)
|
41
44
|
self.extend(moduule)
|
42
45
|
self.send(message, *args)
|
43
46
|
end
|
47
|
+
alias_method :ss, :singleton_send
|
44
48
|
|
45
|
-
|
46
|
-
#
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
# Couldn't get this idea to work:
|
50
|
+
# def singleton_that_accepts_object(object, method_name, *args)
|
51
|
+
## #class << self
|
52
|
+
## #self.instance_eval do
|
53
|
+
## self.class.module_eval do
|
54
|
+
## define_method(:colorize2, object.class.instance_method(:colorize2))
|
55
|
+
## end
|
56
|
+
## # raises "TypeError: bind argument must be an instance of TheTest"
|
57
|
+
#
|
58
|
+
## object.class.instance_method(method_name).
|
59
|
+
## bind(self)
|
60
|
+
## # raises "TypeError: bind argument must be an instance of TheTest"
|
61
|
+
#
|
62
|
+
## self.class.extend(object.class)
|
63
|
+
## self.class.send(:include, object.class)
|
64
|
+
## # raises "TypeError: wrong argument type Class (expected Module)"
|
65
|
+
# self.send(method_name, *args)
|
66
|
+
# end
|
62
67
|
|
63
68
|
end
|
64
69
|
|
@@ -77,13 +82,21 @@ module MyColorizer
|
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
85
|
+
|
86
|
+
#module PresentationLayer
|
87
|
+
# create_module_method :to_currency do
|
88
|
+
# #...
|
89
|
+
# end
|
90
|
+
#end
|
91
|
+
|
92
|
+
|
80
93
|
class TheTest < Test::Unit::TestCase
|
81
94
|
def test_1
|
82
|
-
assert_equal "whatever (colorized in )", "whatever".
|
83
|
-
assert_equal "whatever (colorized in blue)", "whatever".
|
95
|
+
assert_equal "whatever (colorized in )", "whatever".ss(MyColorizer, :colorize)
|
96
|
+
assert_equal "whatever (colorized in blue)", "whatever".singleton_send(MyColorizer, :colorize, :blue)
|
84
97
|
end
|
85
98
|
|
86
|
-
# def
|
99
|
+
# def test_singleton_that_accepts_object
|
87
100
|
# assert_equal "whatever (colorized in )", "whatever".singleton_that_accepts_object(self, :colorize2)
|
88
101
|
# assert_equal "whatever (colorized in blue)", "whatever".singleton_that_accepts_object(self, :colorize2, :blue)
|
89
102
|
# end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
#--
|
1
2
|
# Author:: Tyler Rick
|
2
3
|
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
3
4
|
# License:: Ruby License
|
4
5
|
# Submit to Facets?:: Probably not.
|
5
6
|
# Developer notes:
|
6
7
|
# * Can we use a more general method instead (like humanize or methodize)? Does this really have a use distinct from all the other inflection methods out there?
|
8
|
+
#++
|
7
9
|
|
8
10
|
class String
|
9
11
|
# Strips out most non-alphanumeric characters and leaves you with a lowercased, underscored string that can safely be used as a class_name
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: qualitysmith_extensions
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-03-
|
6
|
+
version: 0.0.4
|
7
|
+
date: 2007-03-21 00:00:00 -07:00
|
8
8
|
summary: A collection of reusable Ruby methods developed by QualitySmith.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,10 +29,8 @@ authors:
|
|
29
29
|
- Tyler Rick and others
|
30
30
|
files:
|
31
31
|
- lib/qualitysmith_extensions/global_variable_set.rb
|
32
|
-
- lib/qualitysmith_extensions/simulate_input.rb
|
33
32
|
- lib/qualitysmith_extensions/collection_extensions_for_cgi.rb
|
34
33
|
- lib/qualitysmith_extensions/all.rb
|
35
|
-
- lib/qualitysmith_extensions/filter_output.rb
|
36
34
|
- lib/qualitysmith_extensions/month.rb
|
37
35
|
- lib/qualitysmith_extensions/test/assert_exception.rb
|
38
36
|
- lib/qualitysmith_extensions/test/assert_user_error.rb
|
@@ -40,9 +38,11 @@ files:
|
|
40
38
|
- lib/qualitysmith_extensions/test/assert_includes.rb
|
41
39
|
- lib/qualitysmith_extensions/file_test/binary_file.rb
|
42
40
|
- lib/qualitysmith_extensions/kernel/require_all.rb
|
41
|
+
- lib/qualitysmith_extensions/kernel/simulate_input.rb
|
43
42
|
- lib/qualitysmith_extensions/kernel/die.rb
|
44
43
|
- lib/qualitysmith_extensions/kernel/require_once.rb
|
45
44
|
- lib/qualitysmith_extensions/kernel/all.rb
|
45
|
+
- lib/qualitysmith_extensions/kernel/filter_output.rb
|
46
46
|
- lib/qualitysmith_extensions/kernel/backtrace.rb
|
47
47
|
- lib/qualitysmith_extensions/kernel/capture_output.rb
|
48
48
|
- lib/qualitysmith_extensions/object/singleton.rb
|