mack_ruby_core_extensions 0.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.
Files changed (75) hide show
  1. data/README +3 -0
  2. data/doc/classes/Array.html +465 -0
  3. data/doc/classes/Class.html +181 -0
  4. data/doc/classes/Dir.html +190 -0
  5. data/doc/classes/Float.html +148 -0
  6. data/doc/classes/Hash.html +232 -0
  7. data/doc/classes/Kernel.html +182 -0
  8. data/doc/classes/Mack.html +111 -0
  9. data/doc/classes/Mack/Utils.html +111 -0
  10. data/doc/classes/Mack/Utils/Inflector.html +422 -0
  11. data/doc/classes/Math.html +188 -0
  12. data/doc/classes/MethodNotImplemented.html +155 -0
  13. data/doc/classes/Module.html +203 -0
  14. data/doc/classes/NilClass.html +151 -0
  15. data/doc/classes/Object.html +315 -0
  16. data/doc/classes/String.html +890 -0
  17. data/doc/classes/Symbol.html +148 -0
  18. data/doc/created.rid +1 -0
  19. data/doc/files/README.html +111 -0
  20. data/doc/files/lib/extensions/array_rb.html +101 -0
  21. data/doc/files/lib/extensions/class_rb.html +101 -0
  22. data/doc/files/lib/extensions/dir_rb.html +101 -0
  23. data/doc/files/lib/extensions/float_rb.html +101 -0
  24. data/doc/files/lib/extensions/hash_rb.html +101 -0
  25. data/doc/files/lib/extensions/kernel_rb.html +109 -0
  26. data/doc/files/lib/extensions/logger_rb.html +101 -0
  27. data/doc/files/lib/extensions/math_rb.html +101 -0
  28. data/doc/files/lib/extensions/method_not_implemented_rb.html +108 -0
  29. data/doc/files/lib/extensions/module_rb.html +101 -0
  30. data/doc/files/lib/extensions/nil_rb.html +101 -0
  31. data/doc/files/lib/extensions/object_rb.html +101 -0
  32. data/doc/files/lib/extensions/string_rb.html +108 -0
  33. data/doc/files/lib/extensions/symbol_rb.html +101 -0
  34. data/doc/files/lib/mack_ruby_core_extensions_rb.html +101 -0
  35. data/doc/files/lib/utils/inflections_rb.html +101 -0
  36. data/doc/files/lib/utils/inflector_rb.html +108 -0
  37. data/doc/fr_class_index.html +42 -0
  38. data/doc/fr_file_index.html +44 -0
  39. data/doc/fr_method_index.html +92 -0
  40. data/doc/index.html +24 -0
  41. data/doc/rdoc-style.css +208 -0
  42. data/lib/extensions/array.rb +101 -0
  43. data/lib/extensions/class.rb +19 -0
  44. data/lib/extensions/dir.rb +25 -0
  45. data/lib/extensions/float.rb +5 -0
  46. data/lib/extensions/hash.rb +47 -0
  47. data/lib/extensions/kernel.rb +30 -0
  48. data/lib/extensions/logger.rb +0 -0
  49. data/lib/extensions/math.rb +15 -0
  50. data/lib/extensions/method_not_implemented.rb +12 -0
  51. data/lib/extensions/module.rb +29 -0
  52. data/lib/extensions/nil.rb +8 -0
  53. data/lib/extensions/object.rb +103 -0
  54. data/lib/extensions/string.rb +261 -0
  55. data/lib/extensions/symbol.rb +7 -0
  56. data/lib/mack_ruby_core_extensions.rb +7 -0
  57. data/lib/utils/inflections.rb +62 -0
  58. data/lib/utils/inflector.rb +129 -0
  59. data/test/extensions/array_test.rb +15 -0
  60. data/test/extensions/class_test.rb +28 -0
  61. data/test/extensions/dir_test.rb +15 -0
  62. data/test/extensions/float_test.rb +15 -0
  63. data/test/extensions/hash_test.rb +34 -0
  64. data/test/extensions/kernel_test.rb +15 -0
  65. data/test/extensions/logger_test.rb +15 -0
  66. data/test/extensions/math_test.rb +15 -0
  67. data/test/extensions/method_not_implemented_test.rb +15 -0
  68. data/test/extensions/module_test.rb +57 -0
  69. data/test/extensions/nil_test.rb +15 -0
  70. data/test/extensions/object_test.rb +15 -0
  71. data/test/extensions/string_test.rb +104 -0
  72. data/test/extensions/symbol_test.rb +15 -0
  73. data/test/test_helper.rb +6 -0
  74. data/test/utils/inflection_test.rb +32 -0
  75. metadata +133 -0
@@ -0,0 +1,7 @@
1
+ class Symbol
2
+
3
+ def methodize
4
+ self.to_s.methodize
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ [:inflector, :inflections].each do |k|
2
+ require "utils/#{k}"
3
+ end
4
+
5
+ [:array, :class, :dir, :float, :hash, :kernel, :logger, :math, :method_not_implemented, :module, :nil, :object, :string, :symbol].each do |k|
6
+ require "extensions/#{k}"
7
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), "inflector")
2
+ # Default inflections. This is taken from Jeremy McAnally's great Rails plugin, acts_as_good_speeler. Thanks Jeremy! http://www.jeremymcanally.com/
3
+ Mack::Utils::Inflector.inflections do |inflect|
4
+ inflect.plural(/$/, 's')
5
+ inflect.plural(/s$/i, 's')
6
+ inflect.plural(/(bu)s$/i, '\1ses')
7
+ inflect.plural(/(stimul|hippopotam|octop|vir|syllab|foc|alumn|fung|radi)us$/i, '\1i')
8
+ inflect.plural(/(ax|test)is$/i, '\1es')
9
+ inflect.plural(/(alias|status)$/i, '\1es')
10
+ inflect.plural(/(buffal|tomat|torped)o$/i, '\1oes')
11
+ inflect.plural(/([dti])um$/i, '\1a')
12
+ inflect.plural(/sis$/i, 'ses')
13
+ inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
14
+ inflect.plural(/(hive)$/i, '\1s')
15
+ inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
16
+ inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
17
+ inflect.plural(/(matr|append|vert|ind)ix|ex$/i, '\1ices')
18
+ inflect.plural(/([m|l])ouse$/i, '\1ice')
19
+ inflect.plural(/^(ox)$/i, '\1en')
20
+ inflect.plural(/(quiz)$/i, '\1zes')
21
+ inflect.plural(/(phenomen|criteri)on$/i, '\1a')
22
+ inflect.plural(/^(?!(.*hu|.*ger|.*sha))(.*)(wom|m)an$/i, '\2\3en')
23
+ inflect.plural(/(curricul|bacteri|medi)um$/i, '\1a')
24
+ inflect.plural(/(nebul|formul|vit|vertebr|alg|alumn)a$/i, '\1ae')
25
+
26
+ inflect.singular(/s$/i, '')
27
+ inflect.singular(/(n)ews$/i, '\1ews')
28
+ inflect.singular(/([dti])a$/i, '\1um')
29
+ inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
30
+ inflect.singular(/(^analy|cri|empha)ses$/i, '\1sis')
31
+ inflect.singular(/([^f])ves$/i, '\1fe')
32
+ inflect.singular(/(hive)s$/i, '\1')
33
+ inflect.singular(/(tive)s$/i, '\1')
34
+ inflect.singular(/(bus)es$/i, '\1')
35
+ inflect.singular(/(o)es$/i, '\1')
36
+ inflect.singular(/(shoe)s$/i, '\1')
37
+ inflect.singular(/(test|ax)es$/i, '\1is')
38
+ inflect.singular(/(stimul|hippopotam|octop|vir|syllab|foc|alumn|fung|radi)i$/i, '\1us')
39
+ inflect.singular(/(alias|status)es$/i, '\1')
40
+ inflect.singular(/^(ox)en$/i, '\1')
41
+ inflect.singular(/(vert|ind)ices$/i, '\1ex')
42
+ inflect.singular(/(matr|append)ices$/i, '\1ix')
43
+ inflect.singular(/(quiz)zes$/i, '\1')
44
+ inflect.singular(/(phenomen|criteri)a$/i, '\1on')
45
+ inflect.singular(/(.*)(wo|m)en$/i, '\1\2an')
46
+ inflect.singular(/(medi|curricul|bacteri)a$/i, '\1um')
47
+ inflect.singular(/(nebula|formula|vita|vertebra|alga|alumna)e$/i, '\1')
48
+ inflect.singular(/^(.*)ookies$/, '\1ookie')
49
+ inflect.singular(/(.*)ss$/, '\1ss')
50
+ inflect.singular(/(.*)ies$/, '\1y')
51
+
52
+ inflect.irregular('person', 'people')
53
+ inflect.irregular('child', 'children')
54
+ inflect.irregular('sex', 'sexes')
55
+ inflect.irregular('move', 'moves')
56
+ inflect.irregular('tooth', 'teeth')
57
+ inflect.irregular('die', 'dice')
58
+ inflect.irregular('talisman', 'talismans')
59
+ inflect.irregular('penis', 'penises')
60
+
61
+ inflect.uncountable(%w(pokemon pokémon equipment information rice money species series fish sheep deer offspring))
62
+ end
@@ -0,0 +1,129 @@
1
+ require 'singleton'
2
+ module Mack
3
+ module Utils
4
+ # This class is used to deal with inflection strings. This means taken a string and make it plural, or singular, etc...
5
+ # Inflection rules can be added very easy, and are checked from the bottom up. This means that the last rule is the first
6
+ # rule to be matched. The exception to this, kind of, is 'irregular' and 'uncountable' rules. The 'uncountable' rules are
7
+ # always checked first, then the 'irregular' rules, and finally either the 'singular' or 'plural' rules, depending on what
8
+ # you're trying to do. Within each of these sets of rules, the last rule in is the first rule matched.
9
+ #
10
+ # Example:
11
+ # Mack::Utils::Inflector.inflections do |inflect|
12
+ # inflect.plural(/$/, 's')
13
+ # inflect.plural(/^(ox)$/i, '\1en')
14
+ # inflect.plural(/(phenomen|criteri)on$/i, '\1a')
15
+ #
16
+ # inflect.singular(/s$/i, '')
17
+ # inflect.singular(/(n)ews$/i, '\1ews')
18
+ # inflect.singular(/^(.*)ookies$/, '\1ookie')
19
+ #
20
+ # inflect.irregular('person', 'people')
21
+ # inflect.irregular('child', 'children')
22
+ #
23
+ # inflect.uncountable(%w(fish sheep deer offspring))
24
+ # end
25
+ class Inflector
26
+ include Singleton
27
+
28
+ def initialize # :nodoc:
29
+ @plural_rules = []
30
+ @singular_rules = []
31
+ @irregular_rules = []
32
+ @uncountable_rules = []
33
+ end
34
+
35
+ # Adds a plural rule to the system.
36
+ #
37
+ # Example:
38
+ # Mack::Utils::Inflector.inflections do |inflect|
39
+ # inflect.plural(/$/, 's')
40
+ # inflect.plural(/^(ox)$/i, '\1en')
41
+ # inflect.plural(/(phenomen|criteri)on$/i, '\1a')
42
+ # end
43
+ def plural(rule, replacement)
44
+ @plural_rules << {:rule => rule, :replacement => replacement}
45
+ end
46
+
47
+ # Adds a singular rule to the system.
48
+ #
49
+ # Example:
50
+ # Mack::Utils::Inflector.inflections do |inflect|
51
+ # inflect.singular(/s$/i, '')
52
+ # inflect.singular(/(n)ews$/i, '\1ews')
53
+ # inflect.singular(/^(.*)ookies$/, '\1ookie')
54
+ # end
55
+ def singular(rule, replacement)
56
+ @singular_rules << {:rule => rule, :replacement => replacement}
57
+ end
58
+
59
+ # Adds a irregular rule to the system.
60
+ #
61
+ # Example:
62
+ # Mack::Utils::Inflector.inflections do |inflect|
63
+ # inflect.irregular('person', 'people')
64
+ # inflect.irregular('child', 'children')
65
+ # end
66
+ def irregular(rule, replacement)
67
+ @irregular_rules << {:rule => rule, :replacement => replacement}
68
+ # do the reverse so you get:
69
+ # person => people
70
+ # people => person
71
+ @irregular_rules << {:rule => replacement, :replacement => rule}
72
+ end
73
+
74
+ # Adds a uncountable word, or words, to the system.
75
+ #
76
+ # Example:
77
+ # Mack::Utils::Inflector.inflections do |inflect|
78
+ # inflect.uncountable(%w(fish sheep deer offspring))
79
+ # end
80
+ def uncountable(*args)
81
+ [args].flatten.each do |word|
82
+ @uncountable_rules << word.downcase
83
+ end
84
+ end
85
+
86
+ # Returns the singular version of the word, if possible.
87
+ #
88
+ # Examples:
89
+ # Mack::Utils::Inflector.instance.singularize("armies") # => "army"
90
+ # Mack::Utils::Inflector.instance.singularize("people") # => "person"
91
+ # Mack::Utils::Inflector.instance.singularize("boats") # => "boat"
92
+ def singularize(word)
93
+ do_work(word, @singular_rules)
94
+ end
95
+
96
+ # Returns the singular version of the word, if possible.
97
+ #
98
+ # Examples:
99
+ # Mack::Utils::Inflector.instance.pluralize("army") # => "armies"
100
+ # Mack::Utils::Inflector.instance.pluralize("person") # => "people"
101
+ # Mack::Utils::Inflector.instance.pluralize("boat") # => "boats"
102
+ def pluralize(word)
103
+ do_work(word, @plural_rules)
104
+ end
105
+
106
+ private
107
+ def do_work(word, specific_rules)
108
+ return word if @uncountable_rules.include?(word.downcase)
109
+ w = word.dup
110
+ [specific_rules, @irregular_rules].flatten.reverse.each do |rule_hash|
111
+ return w if w.gsub!(rule_hash[:rule], rule_hash[:replacement])
112
+ end
113
+ # if all else fails, return the word:
114
+ return word
115
+ end
116
+
117
+ public
118
+ class << self
119
+
120
+ # Yields up Mack::Utils::Inflector.instance
121
+ def inflections
122
+ yield Mack::Utils::Inflector.instance
123
+ end
124
+
125
+ end
126
+
127
+ end # Inflection
128
+ end # Utils
129
+ end # Mack
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class ArrayTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class Fruit
4
+ end
5
+
6
+ class Citrus < Fruit
7
+ end
8
+
9
+ class Orange < Citrus
10
+ end
11
+
12
+ class ClassTest < Test::Unit::TestCase
13
+
14
+ def setup
15
+ end
16
+
17
+ def teardown
18
+ end
19
+
20
+ def test_class_is_a
21
+ assert !Orange.class_is_a?(Array)
22
+ assert Orange.class_is_a?(Orange)
23
+ assert Orange.class_is_a?(Citrus)
24
+ assert Orange.class_is_a?(Fruit)
25
+ assert !Fruit.class_is_a?(Orange)
26
+ end
27
+
28
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class DirTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class FloatTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class HashTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_minus
12
+ h = {:a => "aaa", :b => "bbb", :c => "ccc"}
13
+ assert_equal({:b => "bbb", :c => "ccc"}, (h - :a))
14
+
15
+ h = {:a => "aaa", :b => "bbb", :c => "ccc"}
16
+ assert_equal({:b => "bbb", :c => "ccc"}, (h - [:a]))
17
+
18
+ h = {:a => "aaa", :b => "bbb", :c => "ccc"}
19
+ assert_equal({:c => "ccc"}, (h - [:a, :b]))
20
+
21
+ h = {:a => "aaa", :b => "bbb", :c => "ccc"}
22
+ assert_equal({:a => "aaa", :b => "bbb", :c => "ccc"}, (h - [:d, :e]))
23
+
24
+ h = {:a => "aaa", :b => "bbb", :c => "ccc"}
25
+ assert_equal({:a => "aaa", :b => "bbb", :c => "ccc"}, (h - :d))
26
+ end
27
+
28
+ def test_join
29
+ h = {:rel => "nofollow", :alt => "pickles"}
30
+ # assert_equal "rel=\"nofollow\" alt=\"pickles\"", h.join("%s=\"%s\"", " ")
31
+ assert ("rel=\"nofollow\" alt=\"pickles\"" == h.join("%s=\"%s\"", " ") || "alt=\"pickles\" rel=\"nofollow\"" == h.join("%s=\"%s\"", " "))
32
+ end
33
+
34
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class KernelTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class LoggerTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class MathTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class MethodNotImplementedTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class ModuleTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ module ConvertMyMethodsPlease
12
+ def foo
13
+ end
14
+
15
+ def bar
16
+ end
17
+ end
18
+
19
+ module IncludeMeSafelyPlease
20
+ def foo
21
+ end
22
+
23
+ def bar
24
+ end
25
+ end
26
+
27
+ class LikeToBeSafe
28
+ end
29
+
30
+ def test_convert_security_of_methods
31
+ assert ConvertMyMethodsPlease.public_instance_methods.include?("foo")
32
+ assert ConvertMyMethodsPlease.public_instance_methods.include?("bar")
33
+ ConvertMyMethodsPlease.convert_security_of_methods
34
+ assert !ConvertMyMethodsPlease.public_instance_methods.include?("foo")
35
+ assert !ConvertMyMethodsPlease.public_instance_methods.include?("bar")
36
+ assert ConvertMyMethodsPlease.protected_instance_methods.include?("foo")
37
+ assert ConvertMyMethodsPlease.protected_instance_methods.include?("bar")
38
+ ConvertMyMethodsPlease.convert_security_of_methods(:protected, :private)
39
+ assert !ConvertMyMethodsPlease.protected_instance_methods.include?("foo")
40
+ assert !ConvertMyMethodsPlease.protected_instance_methods.include?("bar")
41
+ assert ConvertMyMethodsPlease.private_instance_methods.include?("foo")
42
+ assert ConvertMyMethodsPlease.private_instance_methods.include?("bar")
43
+ end
44
+
45
+ def test_include_safely_into
46
+ assert IncludeMeSafelyPlease.public_instance_methods.include?("foo")
47
+ assert IncludeMeSafelyPlease.public_instance_methods.include?("bar")
48
+ assert !LikeToBeSafe.public_instance_methods.include?("foo")
49
+ assert !LikeToBeSafe.public_instance_methods.include?("bar")
50
+ IncludeMeSafelyPlease.include_safely_into(LikeToBeSafe)
51
+ assert !LikeToBeSafe.public_instance_methods.include?("foo")
52
+ assert !LikeToBeSafe.public_instance_methods.include?("bar")
53
+ assert LikeToBeSafe.protected_instance_methods.include?("foo")
54
+ assert LikeToBeSafe.protected_instance_methods.include?("bar")
55
+ end
56
+
57
+ end