ruby-nuggets 0.6.2 → 0.6.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/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.6.2
5
+ This documentation refers to ruby-nuggets version 0.6.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -47,7 +47,7 @@ Rubyforge project:: <http://rubyforge.org/projects/prometheus>
47
47
 
48
48
  == LICENSE AND COPYRIGHT
49
49
 
50
- Copyright (C) 2007-2009 Jens Wille
50
+ Copyright (C) 2007-2010 Jens Wille
51
51
 
52
52
  ruby-nuggets is free software: you can redistribute it and/or modify it under
53
53
  the terms of the GNU General Public License as published by the Free Software
data/Rakefile CHANGED
@@ -1,25 +1,25 @@
1
+ require %q{lib/nuggets/version}
2
+
1
3
  begin
2
4
  require 'hen'
5
+
6
+ Hen.lay! {{
7
+ :rubyforge => {
8
+ :project => %q{prometheus},
9
+ :package => %q{ruby-nuggets}
10
+ },
11
+
12
+ :gem => {
13
+ :version => Nuggets::VERSION,
14
+ :summary => 'Some extensions to the Ruby programming language.',
15
+ :files => FileList['lib/**/*.rb'].to_a,
16
+ :extra_files => FileList['[A-Z]*'].to_a
17
+ }
18
+ }}
3
19
  rescue LoadError
4
20
  abort "Please install the 'hen' gem first."
5
21
  end
6
22
 
7
- require 'lib/nuggets/version'
8
-
9
- Hen.lay! {{
10
- :rubyforge => {
11
- :project => %q{prometheus},
12
- :package => %q{ruby-nuggets}
13
- },
14
-
15
- :gem => {
16
- :version => Nuggets::VERSION,
17
- :summary => 'Some extensions to the Ruby programming language.',
18
- :files => FileList['lib/**/*.rb'].to_a,
19
- :extra_files => FileList['[A-Z]*'].to_a
20
- }
21
- }}
22
-
23
23
  desc "Run all specs in isolation"
24
24
  task 'spec:isolated' do
25
25
  ARGV.delete('spec:isolated')
@@ -59,29 +59,23 @@ module Nuggets
59
59
  args = value_keys.dup
60
60
  options = value_keys.last.is_a?(::Hash) ? value_keys.pop : {}
61
61
 
62
- do_sort = if options.has_key?(:sort_by)
62
+ sort_proc = if options.has_key?(:sort_by)
63
63
  lambda { sort_by(&options[:sort_by]) }
64
64
  elsif options.has_key?(:sort)
65
- sort_opt = options[:sort]
66
-
67
- if sort_opt == true
68
- lambda { sort }
69
- elsif sort_opt.respond_to?(:to_proc)
70
- lambda { sort(&sort_opt) }
71
- end
65
+ options[:sort] == true ? lambda { sort } : lambda { sort(&options[:sort]) }
72
66
  end
73
67
 
74
68
  rows = []
75
69
 
76
70
  if values.first.is_a?(self.class) # if any is, then all are
77
- (do_sort ? do_sort.call : self).each { |key, value|
71
+ (sort_proc ? sort_proc.call : self).each { |key, value|
78
72
  value.unroll(*args, &block).each { |row| rows << [key, *row] }
79
73
  }
80
74
  else
81
75
  block[self] if block
82
76
 
83
77
  rows << if value_keys.empty?
84
- do_sort ? do_sort.call.map { |key, value| value } : values
78
+ sort_proc ? sort_proc.call.map { |key, value| value } : values
85
79
  else
86
80
  values_at(*value_keys)
87
81
  end
@@ -4,7 +4,7 @@
4
4
  # A component of ruby-nuggets, some extensions to the Ruby programming #
5
5
  # language. #
6
6
  # #
7
- # Copyright (C) 2007 Jens Wille #
7
+ # Copyright (C) 2007-2010 Jens Wille #
8
8
  # #
9
9
  # Authors: #
10
10
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -40,8 +40,9 @@ class String
40
40
  # substitution]</tt> pairs, or, simply, a hash. Note that, when using a hash,
41
41
  # the ordering of how substitutions are processed might differ from what you
42
42
  # intended -- instead use an array when order matters. +pattern+ can be a
43
- # string or a regexp, +substitution+ may contain string expressions (cf.
44
- # #evaluate).
43
+ # string or a regexp, +substitution+ can be a string (which may contain string
44
+ # expressions; cf. #evaluate), a proc (which will be call()ed), or any object
45
+ # really (which will be converted into a string).
45
46
  def msub(*substitutions)
46
47
  (_dup = dup).msub!(*substitutions) || _dup
47
48
  end
@@ -51,15 +52,12 @@ class String
51
52
  #
52
53
  # Destructive version of #msub.
53
54
  def msub!(*substitutions)
54
- substitutions = substitutions.first if substitutions.first.is_a?(Hash)
55
-
56
- binding = substitutions.is_a?(Hash) ? substitutions.delete(:__binding__) :
57
- substitutions.last.is_a?(Hash) ? substitutions.pop[:__binding__] : nil
58
- binding ||= Kernel.binding
55
+ options = substitutions.last.is_a?(Hash) ? substitutions.pop : {}
56
+ binding = options.delete(:__binding__) || Kernel.binding
59
57
 
60
58
  keys, subs, cache = [], [], {}
61
59
 
62
- substitutions.each { |key, value|
60
+ substitutions.concat(options.to_a).each { |key, value|
63
61
  key = Regexp.new(Regexp.escape(key)) unless key.is_a?(Regexp)
64
62
 
65
63
  keys << key
@@ -68,8 +66,18 @@ class String
68
66
 
69
67
  gsub!(Regexp.union(*keys)) { |match|
70
68
  cache[match] ||= begin
71
- eval("__match__ = #{match.inspect}", binding)
72
- subs.find { |key, _| key =~ match }.last.evaluate(binding)
69
+ value = subs.find { |key, _| key =~ match }.last
70
+
71
+ if value.respond_to?(:evaluate)
72
+ # make match available for string evaluation
73
+ eval("__match__ = #{match.inspect}", binding)
74
+
75
+ value.evaluate(binding)
76
+ elsif value.respond_to?(:call)
77
+ value.call(match)
78
+ else
79
+ value
80
+ end
73
81
  end
74
82
  }
75
83
  end
@@ -87,12 +95,9 @@ if $0 == __FILE__
87
95
  p s
88
96
 
89
97
  t = '!!!'
90
- begin
91
- p s.msub('r' => '???', 'z' => '#{t}')
92
- rescue NameError => err
93
- warn err
94
- end
98
+ begin; p s.msub('r' => '???', 'z' => '#{t}'); rescue NameError => err; warn err; end
95
99
  p s.msub('r' => '???', 'z' => '#{t}', :__binding__ => binding)
96
100
 
97
101
  p s.msub(/[A-Z]/ => '#{__match__.downcase}', :__binding__ => binding)
102
+ p s.msub(/[A-Z]/ => lambda { |match| match.downcase })
98
103
  end
@@ -4,7 +4,7 @@
4
4
  # A component of ruby-nuggets, some extensions to the Ruby programming #
5
5
  # language. #
6
6
  # #
7
- # Copyright (C) 2007-2008 Jens Wille #
7
+ # Copyright (C) 2007-2010 Jens Wille #
8
8
  # #
9
9
  # Authors: #
10
10
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -31,14 +31,8 @@ module Util
31
31
 
32
32
  extend self
33
33
 
34
- COLOUR_RE = %r{\e\[((?:[0-9]|[34][0-7])(?:;(?:[0-9]|[34][0-7]))*)m}
35
-
36
- OPEN = '<span style="'.freeze
37
- OPENC = '">'.freeze
38
- CLOSE = '</span>'.freeze
39
-
40
34
  ATTRIBUTES = {
41
- '0' => CLOSE, # clear
35
+ '0' => nil, # clear
42
36
  '1' => 'font-weight: bold', # bold
43
37
  '2' => '', # dark
44
38
  '3' => 'font-style: italic', # italic -- not widely implemented
@@ -66,15 +60,31 @@ module Util
66
60
  '47' => 'background-color: white' # on white
67
61
  }
68
62
 
63
+ ATTRIBUTES_RE = Regexp.union(*ATTRIBUTES.keys)
64
+
65
+ DELIMITER = ';'
66
+
67
+ COLOR_RE = %r{
68
+ \e \[ ( #{ATTRIBUTES_RE} (?: #{DELIMITER} #{ATTRIBUTES_RE} )* ) m
69
+ }x
70
+
71
+ STYLE = '<span style="%s">'
72
+ CLEAR = '</span>'
73
+
69
74
  def convert(string)
70
- string.gsub(COLOUR_RE) {
71
- subst, attrs = '', $1.split(';')
75
+ string.gsub(COLOR_RE) { format($1.split(DELIMITER).uniq) }
76
+ end
72
77
 
73
- subst << CLOSE if attrs.delete('0')
74
- subst << OPEN << attrs.map { |c| ATTRIBUTES[c] }.join('; ') << OPENC unless attrs.empty?
78
+ def format(attributes)
79
+ "#{clear(attributes)}#{style(attributes) if attributes.any?}"
80
+ end
75
81
 
76
- subst
77
- }
82
+ def clear(attributes)
83
+ CLEAR if attributes.delete('0')
84
+ end
85
+
86
+ def style(attributes)
87
+ STYLE % attributes.map { |code| ATTRIBUTES[code] }.join('; ')
78
88
  end
79
89
 
80
90
  end
@@ -87,4 +97,6 @@ class String
87
97
  Util::ANSIColor2CSS.convert(self)
88
98
  end
89
99
 
100
+ alias_method :ansicolour2css, :ansicolor2css
101
+
90
102
  end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 6
7
- TINY = 2
7
+ TINY = 3
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ hash: 1
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 3
10
+ version: 0.6.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jens Wille
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-29 00:00:00 +01:00
18
+ date: 2010-06-28 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -24,135 +30,141 @@ extra_rdoc_files:
24
30
  - ChangeLog
25
31
  - README
26
32
  files:
27
- - lib/nuggets/env/user_home.rb
28
- - lib/nuggets/env/user_home_mixin.rb
29
- - lib/nuggets/env/user_encoding.rb
30
- - lib/nuggets/env/set_mixin.rb
31
- - lib/nuggets/env/user_encoding_mixin.rb
32
- - lib/nuggets/env/set.rb
33
- - lib/nuggets/numeric/limit.rb
34
- - lib/nuggets/numeric/to_multiple.rb
35
- - lib/nuggets/numeric/between.rb
36
- - lib/nuggets/numeric/duration.rb
37
- - lib/nuggets/numeric/signum.rb
38
- - lib/nuggets/array/to_hash.rb
39
- - lib/nuggets/array/variance.rb
40
- - lib/nuggets/array/runiq_mixin.rb
33
+ - lib/nuggets.rb
34
+ - lib/nuggets/integer/to_binary_s.rb
35
+ - lib/nuggets/integer/factorial.rb
36
+ - lib/nuggets/integer/length_mixin.rb
37
+ - lib/nuggets/integer/length.rb
38
+ - lib/nuggets/util/added_methods/init.rb
39
+ - lib/nuggets/util/i18n.rb
40
+ - lib/nuggets/util/dotted_decimal.rb
41
+ - lib/nuggets/util/content_type.rb
42
+ - lib/nuggets/util/ansicolor2css.rb
43
+ - lib/nuggets/util/added_methods.rb
41
44
  - lib/nuggets/array/shuffle.rb
42
45
  - lib/nuggets/array/variance_mixin.rb
43
- - lib/nuggets/array/standard_deviation_mixin.rb
44
- - lib/nuggets/array/limit.rb
45
46
  - lib/nuggets/array/format.rb
47
+ - lib/nuggets/array/to_hash.rb
48
+ - lib/nuggets/array/rand.rb
49
+ - lib/nuggets/array/runiq.rb
46
50
  - lib/nuggets/array/monotone.rb
47
- - lib/nuggets/array/only.rb
51
+ - lib/nuggets/array/combination.rb
48
52
  - lib/nuggets/array/flatten_once.rb
49
- - lib/nuggets/array/runiq.rb
53
+ - lib/nuggets/array/standard_deviation_mixin.rb
54
+ - lib/nuggets/array/variance.rb
55
+ - lib/nuggets/array/limit.rb
50
56
  - lib/nuggets/array/standard_deviation.rb
51
- - lib/nuggets/array/rand.rb
52
- - lib/nuggets/array/combination.rb
53
57
  - lib/nuggets/array/limit_mixin.rb
54
58
  - lib/nuggets/array/in_order.rb
55
- - lib/nuggets/hash/unroll_mixin.rb
56
- - lib/nuggets/hash/only.rb
57
- - lib/nuggets/hash/at.rb
58
- - lib/nuggets/hash/insert.rb
59
+ - lib/nuggets/array/runiq_mixin.rb
60
+ - lib/nuggets/array/only.rb
61
+ - lib/nuggets/proc/bind_mixin.rb
62
+ - lib/nuggets/proc/bind.rb
59
63
  - lib/nuggets/hash/nest_mixin.rb
64
+ - lib/nuggets/hash/insert.rb
60
65
  - lib/nuggets/hash/unroll.rb
66
+ - lib/nuggets/hash/unroll_mixin.rb
61
67
  - lib/nuggets/hash/nest.rb
68
+ - lib/nuggets/hash/at.rb
62
69
  - lib/nuggets/hash/in_order.rb
63
- - lib/nuggets/enumerable/agrep.rb
70
+ - lib/nuggets/hash/only.rb
64
71
  - lib/nuggets/enumerable/all_any_extended.rb
65
72
  - lib/nuggets/enumerable/minmax.rb
66
- - lib/nuggets/io/agrep.rb
67
- - lib/nuggets/io/modes.rb
68
- - lib/nuggets/all.rb
69
- - lib/nuggets/all_mixins.rb
70
- - lib/nuggets/uri/content_type.rb
71
- - lib/nuggets/uri/exist.rb
72
- - lib/nuggets/uri/content_type_mixin.rb
73
- - lib/nuggets/uri/exist_mixin.rb
74
- - lib/nuggets/string/msub.rb
73
+ - lib/nuggets/enumerable/agrep.rb
74
+ - lib/nuggets/tempfile/open.rb
75
+ - lib/nuggets/file/which.rb
76
+ - lib/nuggets/file/which_mixin.rb
77
+ - lib/nuggets/numeric/between.rb
78
+ - lib/nuggets/numeric/signum.rb
79
+ - lib/nuggets/numeric/limit.rb
80
+ - lib/nuggets/numeric/duration.rb
81
+ - lib/nuggets/numeric/to_multiple.rb
82
+ - lib/nuggets/string/xor_mixin.rb
75
83
  - lib/nuggets/string/capitalize_first.rb
76
- - lib/nuggets/string/wc_mixin.rb
77
84
  - lib/nuggets/string/evaluate.rb
85
+ - lib/nuggets/string/wc_mixin.rb
86
+ - lib/nuggets/string/nsub.rb
87
+ - lib/nuggets/string/xor.rb
78
88
  - lib/nuggets/string/case.rb
89
+ - lib/nuggets/string/msub.rb
79
90
  - lib/nuggets/string/wc.rb
80
91
  - lib/nuggets/string/sub_with_md.rb
81
- - lib/nuggets/string/nsub.rb
82
- - lib/nuggets/string/xor_mixin.rb
83
- - lib/nuggets/string/xor.rb
84
92
  - lib/nuggets/string/word_wrap.rb
85
- - lib/nuggets/integer/length.rb
86
- - lib/nuggets/integer/to_binary_s.rb
87
- - lib/nuggets/integer/length_mixin.rb
88
- - lib/nuggets/integer/factorial.rb
89
- - lib/nuggets/object/singleton_class_mixin.rb
90
- - lib/nuggets/object/uniclass.rb
93
+ - lib/nuggets/io/agrep.rb
94
+ - lib/nuggets/io/modes.rb
95
+ - lib/nuggets/env/user_home_mixin.rb
96
+ - lib/nuggets/env/set.rb
97
+ - lib/nuggets/env/user_encoding_mixin.rb
98
+ - lib/nuggets/env/set_mixin.rb
99
+ - lib/nuggets/env/user_home.rb
100
+ - lib/nuggets/env/user_encoding.rb
101
+ - lib/nuggets/all_mixins.rb
102
+ - lib/nuggets/uri/exist_mixin.rb
103
+ - lib/nuggets/uri/content_type_mixin.rb
104
+ - lib/nuggets/uri/exist.rb
105
+ - lib/nuggets/uri/content_type.rb
106
+ - lib/nuggets/range/quantile_mixin.rb
107
+ - lib/nuggets/range/quantile.rb
108
+ - lib/nuggets/all.rb
109
+ - lib/nuggets/version.rb
91
110
  - lib/nuggets/object/virtual_class.rb
92
- - lib/nuggets/object/silence_mixin.rb
93
- - lib/nuggets/object/msend_mixin.rb
111
+ - lib/nuggets/object/uniclass.rb
94
112
  - lib/nuggets/object/blank.rb
95
- - lib/nuggets/object/ghost_class.rb
96
- - lib/nuggets/object/metaclass.rb
113
+ - lib/nuggets/object/msend.rb
97
114
  - lib/nuggets/object/singleton_class.rb
98
- - lib/nuggets/object/silence.rb
99
- - lib/nuggets/object/eigenclass.rb
100
115
  - lib/nuggets/object/boolean_mixin.rb
101
- - lib/nuggets/object/blank_mixin.rb
102
- - lib/nuggets/object/msend.rb
116
+ - lib/nuggets/object/silence_mixin.rb
103
117
  - lib/nuggets/object/boolean.rb
104
- - lib/nuggets/proc/bind_mixin.rb
105
- - lib/nuggets/proc/bind.rb
106
- - lib/nuggets/range/quantile_mixin.rb
107
- - lib/nuggets/range/quantile.rb
108
- - lib/nuggets/util/added_methods.rb
109
- - lib/nuggets/util/content_type.rb
110
- - lib/nuggets/util/dotted_decimal.rb
111
- - lib/nuggets/util/ansicolor2css.rb
112
- - lib/nuggets/util/i18n.rb
113
- - lib/nuggets/util/added_methods/init.rb
114
- - lib/nuggets/version.rb
115
- - lib/nuggets/tempfile/open.rb
116
- - lib/nuggets/file/which_mixin.rb
117
- - lib/nuggets/file/which.rb
118
- - lib/nuggets.rb
118
+ - lib/nuggets/object/ghost_class.rb
119
+ - lib/nuggets/object/silence.rb
120
+ - lib/nuggets/object/msend_mixin.rb
121
+ - lib/nuggets/object/blank_mixin.rb
122
+ - lib/nuggets/object/singleton_class_mixin.rb
123
+ - lib/nuggets/object/eigenclass.rb
124
+ - lib/nuggets/object/metaclass.rb
125
+ - README
126
+ - ChangeLog
119
127
  - Rakefile
120
128
  - COPYING
121
- - ChangeLog
122
- - README
123
129
  has_rdoc: true
124
130
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
125
131
  licenses: []
126
132
 
127
133
  post_install_message:
128
134
  rdoc_options:
129
- - --title
130
- - ruby-nuggets Application documentation
131
- - --main
132
- - README
133
135
  - --line-numbers
134
136
  - --inline-source
135
- - --all
137
+ - --main
138
+ - README
136
139
  - --charset
137
140
  - UTF-8
141
+ - --title
142
+ - ruby-nuggets Application documentation
143
+ - --all
138
144
  require_paths:
139
145
  - lib
140
146
  required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
141
148
  requirements:
142
149
  - - ">="
143
150
  - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
144
154
  version: "0"
145
- version:
146
155
  required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
147
157
  requirements:
148
158
  - - ">="
149
159
  - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
150
163
  version: "0"
151
- version:
152
164
  requirements: []
153
165
 
154
166
  rubyforge_project: prometheus
155
- rubygems_version: 1.3.5
167
+ rubygems_version: 1.3.7
156
168
  signing_key:
157
169
  specification_version: 3
158
170
  summary: Some extensions to the Ruby programming language.