blackwinter-ruby-nuggets 0.5.4 → 0.5.5
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 +1 -1
- data/lib/nuggets/string/wc.rb +5 -0
- data/lib/nuggets/string/wc_mixin.rb +96 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +6 -4
data/README
CHANGED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#--
|
|
2
|
+
###############################################################################
|
|
3
|
+
# #
|
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
+
# language. #
|
|
6
|
+
# #
|
|
7
|
+
# Copyright (C) 2007-2009 Jens Wille #
|
|
8
|
+
# #
|
|
9
|
+
# Authors: #
|
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
|
11
|
+
# #
|
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
|
15
|
+
# any later version. #
|
|
16
|
+
# #
|
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
20
|
+
# more details. #
|
|
21
|
+
# #
|
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
+
# #
|
|
25
|
+
###############################################################################
|
|
26
|
+
#++
|
|
27
|
+
|
|
28
|
+
module Nuggets
|
|
29
|
+
class String
|
|
30
|
+
module WcMixin
|
|
31
|
+
|
|
32
|
+
# call-seq:
|
|
33
|
+
# str.wc => anArray
|
|
34
|
+
#
|
|
35
|
+
# Count number of lines, words, and bytes in _str_.
|
|
36
|
+
def wc
|
|
37
|
+
[wc_l, wc_w, wc_c]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# call-seq:
|
|
41
|
+
# str.line_count => anInteger
|
|
42
|
+
#
|
|
43
|
+
# Count number of lines in _str_.
|
|
44
|
+
def line_count
|
|
45
|
+
count_by_re(/#{$/}/)
|
|
46
|
+
end
|
|
47
|
+
alias_method :wc_l, :line_count
|
|
48
|
+
|
|
49
|
+
# call-seq:
|
|
50
|
+
# str.word_count => anInteger
|
|
51
|
+
#
|
|
52
|
+
# Count number of words in _str_.
|
|
53
|
+
def word_count
|
|
54
|
+
count_by_re(/\S+/)
|
|
55
|
+
end
|
|
56
|
+
alias_method :wc_w, :word_count
|
|
57
|
+
|
|
58
|
+
# call-seq:
|
|
59
|
+
# str.byte_count => anInteger
|
|
60
|
+
#
|
|
61
|
+
# Count number of bytes in _str_.
|
|
62
|
+
def byte_count
|
|
63
|
+
respond_to?(:bytesize) ? bytesize : count_by_re(//n) - 1
|
|
64
|
+
end
|
|
65
|
+
alias_method :wc_c, :byte_count
|
|
66
|
+
|
|
67
|
+
# call-seq:
|
|
68
|
+
# str.char_count => anInteger
|
|
69
|
+
#
|
|
70
|
+
# Count number of characters in _str_.
|
|
71
|
+
def char_count
|
|
72
|
+
count_by_re(/./m)
|
|
73
|
+
end
|
|
74
|
+
alias_method :wc_m, :char_count
|
|
75
|
+
|
|
76
|
+
# call-seq:
|
|
77
|
+
# str.count_by_re(re) => anInteger
|
|
78
|
+
#
|
|
79
|
+
# Count number of occurrences of +re+ in _str_.
|
|
80
|
+
def count_by_re(re)
|
|
81
|
+
scan(re).size
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# call-seq:
|
|
85
|
+
# str.count_by_re2(re) => anInteger
|
|
86
|
+
#
|
|
87
|
+
# A more memory-efficient version of #count_by_re.
|
|
88
|
+
def count_by_re2(re)
|
|
89
|
+
count = 0
|
|
90
|
+
scan(re) { |_| count += 1 }
|
|
91
|
+
count
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blackwinter-ruby-nuggets
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jens Wille
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-04-23 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -61,8 +61,10 @@ files:
|
|
|
61
61
|
- lib/nuggets/uri/exist_mixin.rb
|
|
62
62
|
- lib/nuggets/string/msub.rb
|
|
63
63
|
- lib/nuggets/string/capitalize_first.rb
|
|
64
|
+
- lib/nuggets/string/wc_mixin.rb
|
|
64
65
|
- lib/nuggets/string/evaluate.rb
|
|
65
66
|
- lib/nuggets/string/case.rb
|
|
67
|
+
- lib/nuggets/string/wc.rb
|
|
66
68
|
- lib/nuggets/string/sub_with_md.rb
|
|
67
69
|
- lib/nuggets/string/nsub.rb
|
|
68
70
|
- lib/nuggets/string/word_wrap.rb
|
|
@@ -113,8 +115,8 @@ rdoc_options:
|
|
|
113
115
|
- UTF-8
|
|
114
116
|
- --main
|
|
115
117
|
- README
|
|
116
|
-
- --all
|
|
117
118
|
- --line-numbers
|
|
119
|
+
- --all
|
|
118
120
|
require_paths:
|
|
119
121
|
- lib
|
|
120
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
@@ -134,7 +136,7 @@ requirements: []
|
|
|
134
136
|
rubyforge_project: prometheus
|
|
135
137
|
rubygems_version: 1.2.0
|
|
136
138
|
signing_key:
|
|
137
|
-
specification_version:
|
|
139
|
+
specification_version: 3
|
|
138
140
|
summary: Some extensions to the Ruby programming language.
|
|
139
141
|
test_files: []
|
|
140
142
|
|