quality_extensions 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,8 @@
7
7
 
8
8
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
9
9
  require 'rubygems'
10
- require 'facets/ruby' # to_proc
11
- require 'facets/kernel/load'
10
+ require 'facets/symbol/to_proc'
11
+ require 'facets/kernel/require_local'
12
12
  require_local '../string/shell_escape.rb'
13
13
 
14
14
  require 'pp'
@@ -38,10 +38,11 @@
38
38
  #
39
39
  # Conclusion: Chaining is impossible -- Just use _? on any object that might return nil (on which you want to call a method).
40
40
 
41
+ # TODO: figure out why the test started failing
41
42
 
42
43
  require 'singleton'
43
44
  require 'rubygems'
44
- require 'facets/more/basicobject'
45
+ require 'facets/basicobject'
45
46
 
46
47
 
47
48
  class Object
@@ -11,7 +11,7 @@ require 'rubygems'
11
11
  gem 'colored'
12
12
  require 'colored'
13
13
  gem 'facets'
14
- require 'facets/module/alias'
14
+ require 'facets/module/alias_method_chain'
15
15
  require 'quality_extensions/module/guard_method'
16
16
 
17
17
  class String
@@ -32,7 +32,7 @@
32
32
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
33
33
  require 'shellwords'
34
34
  require 'rubygems'
35
- require 'facets/style' #modulize
35
+ require 'facets/string/style' #modulize
36
36
  require 'escape' # http://www.a-k-r.org/escape/
37
37
 
38
38
  # TODO Test
@@ -8,7 +8,7 @@
8
8
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
9
9
  require 'date'
10
10
  require 'rubygems'
11
- require 'facets/date'
11
+ require 'facets/date' # I'm guessing this used to provide iso8601 ... no longer does?
12
12
 
13
13
  class Date
14
14
  def iso8601
@@ -9,7 +9,7 @@
9
9
 
10
10
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
11
11
  require 'rubygems'
12
- require 'facets/module/alias'
12
+ require 'facets/module/alias_method_chain'
13
13
 
14
14
  class Exception
15
15
  # Use this if you want to output an exception with all the details that you'd *normally* see if the exception went unrescued
@@ -0,0 +1,78 @@
1
+ #--
2
+ # Credits::
3
+ # Copyright:: Tyler Rick
4
+ # License:: Ruby License
5
+ # Submit to Facets?:: Maybe
6
+ # Developer notes::
7
+ #++
8
+
9
+ require 'rubygems'
10
+ require 'facets/numeric/round'
11
+ require 'quality_extensions/module/alias_method_chain'
12
+
13
+ # * http://www.oreillynet.com/ruby/blog/2005/12/adding_utility_to_core_classes_1.html
14
+ #class Float
15
+ # def round_to(x = nil)
16
+ # if x > 0
17
+ # ("%.0#{x.to_i}f" % self).to_f
18
+ # else
19
+ # # http://www.oreillynet.com/ruby/blog/2005/12/adding_utility_to_core_classes_1.html
20
+ # # An advantage (I think) of Jonas' solution is it allows rounding on the other side of the decimal when x is negative.
21
+ # # 1234.567.prec(-2) #=>1200.0
22
+ # puts (self * 10**x).to_i
23
+ # puts (10**x).to_f
24
+ # (self * 10**x).round / (10**x)
25
+ # end
26
+ # end
27
+ #end
28
+
29
+ # File lib/core/facets/float/round.rb, line 17
30
+ # def round_at( d ) #d=0
31
+ # (self * (10.0 ** d)).round.to_f / (10.0 ** d)
32
+ # end
33
+
34
+ class Float
35
+ def truncate_with_precision(d)
36
+ (self * (10.0 ** d)).truncate_without_precision.to_f / (10.0 ** d)
37
+ end
38
+ alias_method_chain :truncate, :precision
39
+ end
40
+
41
+
42
+ # _____ _
43
+ # |_ _|__ ___| |_
44
+ # | |/ _ \/ __| __|
45
+ # | | __/\__ \ |_
46
+ # |_|\___||___/\__|
47
+ #
48
+ =begin test
49
+ require 'test/unit'
50
+
51
+ class TheTest < Test::Unit::TestCase
52
+ def test_0
53
+ assert_equal 1234.0, 1234.567.truncate(0)
54
+ assert_equal 1235.0, 1234.567.round_at(0)
55
+ end
56
+
57
+ def test_1
58
+ assert_equal 1234.5, 1234.567.truncate(1)
59
+ assert_equal 1234.6, 1234.567.round_at(1)
60
+ end
61
+
62
+ def test_2
63
+ assert_equal 1234.56, 1234.567.truncate(2)
64
+ assert_equal 1234.57, 1234.567.round_at(2)
65
+ end
66
+
67
+ def test_negative_1
68
+ assert_equal 1230.0, 1235.567.truncate(-1)
69
+ assert_equal 1240.0, 1235.567.round_at(-1)
70
+ end
71
+
72
+ def test_negative_2
73
+ assert_equal 1200.0, 1254.567.truncate(-2)
74
+ assert_equal 1300.0, 1254.567.round_at(-2)
75
+ end
76
+ end
77
+ =end
78
+
@@ -8,7 +8,7 @@
8
8
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
9
9
  autoload :CGI, 'cgi'
10
10
  require 'rubygems'
11
- require 'facets/kernel/load'
11
+ require 'facets/kernel/require_local'
12
12
  require_local '../array/to_query_string.rb'
13
13
 
14
14
  class Hash
@@ -40,7 +40,7 @@ end
40
40
  =begin test
41
41
  require 'test/unit'
42
42
  require "rubygems"
43
- require "facets/ruby" # lines
43
+ require "facets/string/lines"
44
44
 
45
45
  class TheTest < Test::Unit::TestCase
46
46
  def test_1_level
@@ -25,7 +25,7 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
25
25
  require 'test/unit'
26
26
  require 'rubygems'
27
27
  require 'quality_extensions/kernel/capture_output'
28
- #require 'facets/kernel/load'
28
+ #require 'facets/kernel/require_local'
29
29
  #require_local './capture_output'
30
30
 
31
31
  class TheTest < Test::Unit::TestCase
@@ -4,8 +4,8 @@
4
4
  # License:: Ruby License
5
5
  # Submit to Facets?:: Yes
6
6
  # Developer notes::
7
- # * Can anyone think of a better name than put_statement?
8
- # * Something more like xmp? sp? stp? xm? putst? -- Too cryptic?
7
+ # * Can anyone think of a better name than put_statement or stp?
8
+ # * Something more like xmp (eXaMple_Put)... sp? stp? xm? putst? -- Too cryptic?
9
9
  # * verbose? -- too ambiguous (that could be the name for xmp, for example)
10
10
  # * xmp: Do the set_trace_func trick that irb_xmp/of_caller both use... so that the user doesn't have to pass in the local binding manually...
11
11
  # * Add class method for ExamplePrinter to set a template for use by xmp? So if you don't like the default ("=> #{result}"), you can specify your own...
@@ -13,6 +13,7 @@
13
13
 
14
14
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
15
15
  require 'rubygems'
16
+ require 'quality_extensions/module/attribute_accessors'
16
17
  #require 'facets/binding/self/of_caller'
17
18
 
18
19
  # This was written because the irb/xmp that was already available seemed to be
@@ -26,22 +27,26 @@ module ExamplePrinter
26
27
  # xmp 'o = C.new', binding
27
28
  # # => o = C.new
28
29
  def put_statement(code, binding = nil, file = __FILE__, line = __LINE__)
29
- # # This didn't work. Still got this error: undefined local variable or method `x' for #<TheTest:0xb7dbc358> (NameError)
30
- # Binding.of_caller do |caller_binding|
31
- # #puts caller_binding
32
- # puts code
33
- # eval code, caller_binding
34
- # end
30
+
31
+ # We'd like to be able to just use the binding of the caller without passing it in, but unfortunately I don't know how (yet)...
32
+ ## This didn't work. Still got this error: undefined local variable or method `x' for #<TheTest:0xb7dbc358> (NameError)
33
+ #Binding.of_caller do |caller_binding|
34
+ # #puts caller_binding
35
+ # puts code
36
+ # eval code, caller_binding
37
+ #end
38
+
35
39
  puts code
36
40
  eval code, binding, file, line
37
41
  end
38
42
  alias_method :stp, :put_statement
39
43
 
44
+
40
45
  # Prints the given statement (+code+ -- a string) before evaluating it. Then prints its return value.
41
46
  # Pretty much compatible with irb/xmp. But you have currently have to pass
42
47
  # in the binding manually if you have any local variables/methods that xmp
43
48
  # should have access to.
44
- def xmp(code, binding = nil)
49
+ def xmp(code, binding = nil, options = {})
45
50
  result = put_statement(code, binding)
46
51
  puts "=> #{result}"
47
52
  end
@@ -9,7 +9,7 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
9
9
  require 'rubygems'
10
10
  require 'facets/filelist'
11
11
 
12
- require 'facets/kernel/load'
12
+ require 'facets/kernel/require_local'
13
13
  require_local '../file/exact_match_regexp'
14
14
 
15
15
  module Kernel
@@ -10,7 +10,7 @@
10
10
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
11
11
  require 'rubygems'
12
12
  gem 'facets'
13
- require 'facets/module/alias'
13
+ require 'facets/module/alias_method_chain'
14
14
  require 'facets/kernel/singleton_class'
15
15
 
16
16
 
@@ -28,7 +28,7 @@ require 'rubygems'
28
28
  require 'quality_extensions/hash/assert_has_only_keys'
29
29
  require 'facets/hash/merge'
30
30
  require 'facets/kernel/constant'
31
- require 'facets/ruby' # to_proc
31
+ require 'facets/symbol/to_proc'
32
32
  require 'quality_extensions/module/split'
33
33
  require 'quality_extensions/module/basename'
34
34
  require 'quality_extensions/module/dirname'
@@ -14,7 +14,7 @@
14
14
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
15
15
  require 'rubygems'
16
16
  require 'quality_extensions/module/attribute_accessors'
17
- require 'facets/kernel/load'
17
+ require 'facets/kernel/require_local'
18
18
  require_local 'bool_attr_accessor'
19
19
  #require 'quality_extensions/module/bool_attr_accessor'
20
20
  require 'quality_extensions/symbol/match'
@@ -9,7 +9,7 @@
9
9
 
10
10
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
11
11
  require 'rubygems'
12
- require 'facets/ruby' # to_proc
12
+ require 'facets/symbol/to_proc'
13
13
  require 'quality_extensions/symbol/constantize'
14
14
  require 'quality_extensions/module/namespace' # dirname
15
15
  require 'quality_extensions/module/basename'
@@ -11,7 +11,7 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
11
11
  require 'rubygems'
12
12
  gem 'facets'
13
13
  require 'facets/kernel/singleton_class'
14
- require 'facets/module/alias'
14
+ require 'facets/module/alias_method_chain'
15
15
 
16
16
  class Module
17
17
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
10
  require 'rubygems'
11
- require 'facets/ruby' # to_proc
11
+ require 'facets/symbol/to_proc'
12
12
 
13
13
  class Module
14
14
  # Very similar to Facets' +Module#nesting+, but, whereas +nesting+ will break <tt>A::B</tt> into an array of _constants_ represting nesting
@@ -35,7 +35,7 @@ require 'test/unit'
35
35
  require 'rubygems'
36
36
  require 'quality_extensions/test/assert_exception'
37
37
  require 'quality_extensions/test/assert_includes'
38
- require 'facets/module/alias'
38
+ require 'facets/module/alias_method_chain'
39
39
 
40
40
 
41
41
  module MyColorizer
@@ -8,8 +8,8 @@
8
8
 
9
9
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
10
  require 'rubygems'
11
- require 'facets/module/alias'
12
- require 'facets/ruby' # to_proc
11
+ require 'facets/module/alias_method_chain'
12
+ require 'facets/symbol/to_proc'
13
13
 
14
14
  class Object
15
15
 
@@ -8,8 +8,8 @@
8
8
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
9
9
  require 'rubygems'
10
10
  require 'escape' # http://www.a-k-r.org/escape/
11
- require 'facets/ruby' unless Symbol.method_defined?(:to_proc)
12
- require 'facets/kernel/load'
11
+ require 'facets/symbol/to_proc'
12
+ require 'facets/kernel/require_local'
13
13
 
14
14
  class String
15
15
  def shell_escape
@@ -24,8 +24,15 @@ module WithKnowledgeOfColor
24
24
  self.scan(Color_regexp).join
25
25
  end
26
26
 
27
- def ljust_without_color(width)
28
- ljust(width + nonprinting_characters_used_for_color.length)
27
+ def ljust_with_color(width, padstr=' ')
28
+ #ljust(width + nonprinting_characters_used_for_color.length, padstr)
29
+ # That didn't work when you wanted the padstr to have color (as in ' '.on_blue)
30
+
31
+ self + padstr*(width - length_without_color)
32
+ end
33
+
34
+ def rjust_with_color(width, padstr=' ')
35
+ padstr*(width - length_without_color) + self
29
36
  end
30
37
  end
31
38
 
@@ -57,10 +64,17 @@ class TheTest < Test::Unit::TestCase
57
64
  def test_nonprinting_characters_used_for_color
58
65
  assert_equal "\e[34m\e[0m", 'abc'.blue.nonprinting_characters_used_for_color
59
66
  end
60
- def test_ljust_without_color
67
+ def test_ljust_with_color
61
68
  assert_equal "abc ", 'abc'. ljust( 5)
62
- assert_equal "abc ", 'abc'.blue.ljust_without_color(5).strip_color
63
- assert_equal "\e[34mabc\e[0m ", 'abc'.blue.ljust_without_color(5)
69
+ assert_equal "abc ", 'abc'.blue.ljust_with_color(5).strip_color
70
+ assert_equal "\e[34mabc\e[0m ", 'abc'.blue.ljust_with_color(5)
71
+ assert_equal "\e[34mabc\e[0m\e[44m \e[0m\e[44m \e[0m", 'abc'.blue.ljust_with_color(5, ' '.on_blue)
72
+ end
73
+ def test_rjust_with_color
74
+ assert_equal " abc", 'abc'. rjust( 5)
75
+ assert_equal " abc", 'abc'.blue.rjust_with_color(5).strip_color
76
+ assert_equal " \e[34mabc\e[0m", 'abc'.blue.rjust_with_color(5)
77
+ assert_equal "\e[44m \e[0m\e[44m \e[0m\e[34mabc\e[0m", 'abc'.blue.rjust_with_color(5, ' '.on_blue)
64
78
  end
65
79
 
66
80
  end
@@ -9,7 +9,7 @@
9
9
 
10
10
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
11
11
  require 'rubygems'
12
- require 'facets/module/alias'
12
+ require 'facets/module/alias_method_chain'
13
13
 
14
14
  unless defined?(Symbol::HasSymbolSupport)
15
15
 
@@ -13,7 +13,7 @@ require 'rubygems'
13
13
  gem 'colored'
14
14
  require 'colored'
15
15
  gem 'facets'
16
- require 'facets/module/alias'
16
+ require 'facets/module/alias_method_chain'
17
17
  require 'quality_extensions/object/send_if'
18
18
  require 'quality_extensions/string/each_char_with_index'
19
19
  require 'quality_extensions/module/bool_attr_accessor'
metadata CHANGED
@@ -1,34 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: quality_extensions
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.0.3
7
- date: 2008-06-20 00:00:00 -07:00
8
- summary: A collection of reusable Ruby methods which are not (yet) in Facets.
9
- require_paths:
10
- - lib
11
- email: rubyforge.org@tylerrick.com
12
- homepage: http://quality-ext.rubyforge.org/
13
- rubyforge_project: quality_extensions
14
- description: A collection of reusable Ruby methods which are not (yet) in Facets.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.1.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Tyler Rick and others
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A collection of reusable Ruby methods which are not (yet) in Facets.
17
+ email: rubyforge.org@tylerrick.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - Readme
31
24
  files:
25
+ - lib/quality_extensions/float/truncate.rb
32
26
  - lib/quality_extensions/module/attribute_accessors.rb
33
27
  - lib/quality_extensions/module/parents.rb
34
28
  - lib/quality_extensions/module/namespace.rb
@@ -136,21 +130,35 @@ files:
136
130
  - lib/quality_extensions/file/exact_match_regexp.rb
137
131
  - test/all.rb
138
132
  - Readme
139
- test_files:
140
- - test/all.rb
133
+ has_rdoc: true
134
+ homepage: http://quality-ext.rubyforge.org/
135
+ post_install_message:
141
136
  rdoc_options:
142
137
  - --title
143
138
  - quality_extensions
144
139
  - --main
145
140
  - Readme
146
141
  - --line-numbers
147
- extra_rdoc_files:
148
- - Readme
149
- executables: []
150
-
151
- extensions: []
152
-
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: "0"
149
+ version:
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: "0"
155
+ version:
153
156
  requirements: []
154
157
 
155
- dependencies: []
156
-
158
+ rubyforge_project: quality_extensions
159
+ rubygems_version: 1.2.0
160
+ signing_key:
161
+ specification_version: 2
162
+ summary: A collection of reusable Ruby methods which are not (yet) in Facets.
163
+ test_files:
164
+ - test/all.rb