facets 2.4.2 → 2.4.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/AUTHORS +1 -1
- data/CHANGES +25 -5
- data/MANIFEST +67 -34
- data/METADATA +2 -2
- data/NEWS +54 -46
- data/doc/news/NEWS-2.4.0 +52 -0
- data/doc/rdoc/core/classes/Array.html +198 -198
- data/doc/rdoc/core/classes/Binding.html +86 -192
- data/doc/rdoc/core/classes/Class.html +136 -136
- data/doc/rdoc/core/classes/Comparable.html +45 -45
- data/doc/rdoc/core/classes/Dir.html +64 -64
- data/doc/rdoc/core/classes/Enumerable.html +287 -281
- data/doc/rdoc/core/classes/Exception.html +16 -16
- data/doc/rdoc/core/classes/FalseClass.html +8 -8
- data/doc/rdoc/core/classes/File.html +100 -100
- data/doc/rdoc/core/classes/FileTest.html +8 -8
- data/doc/rdoc/core/classes/Float.html +32 -32
- data/doc/rdoc/core/classes/Friend.html +8 -8
- data/doc/rdoc/core/classes/Functor.html +12 -12
- data/doc/rdoc/core/classes/Hash.html +439 -847
- data/doc/rdoc/{more → core}/classes/Indexable.html +115 -115
- data/doc/rdoc/core/classes/InstanceVariables.html +88 -88
- data/doc/rdoc/core/classes/Integer.html +142 -142
- data/doc/rdoc/core/classes/Kernel.html +602 -600
- data/doc/rdoc/core/classes/Lazy/Promise.html +1 -1
- data/doc/rdoc/core/classes/MatchData.html +30 -30
- data/doc/rdoc/core/classes/Module.html +379 -327
- data/doc/rdoc/core/classes/NilClass.html +32 -32
- data/doc/rdoc/core/classes/Numeric.html +46 -46
- data/doc/rdoc/core/classes/Object.html +4 -4
- data/doc/rdoc/core/classes/Proc.html +46 -134
- data/doc/rdoc/core/classes/Range.html +60 -60
- data/doc/rdoc/core/classes/Regexp.html +28 -28
- data/doc/rdoc/{more → core}/classes/Stackable.html +38 -38
- data/doc/rdoc/core/classes/String.html +844 -504
- data/doc/rdoc/core/classes/Symbol.html +62 -62
- data/doc/rdoc/core/classes/Time.html +112 -112
- data/doc/rdoc/core/classes/TrueClass.html +8 -8
- data/doc/rdoc/core/classes/UnboundMethod.html +22 -22
- data/doc/rdoc/core/created.rid +1 -1
- data/doc/rdoc/core/files/lib/core/facets/array_rb.html +4 -1
- data/doc/rdoc/core/files/lib/core/facets/binding_rb.html +1 -1
- data/doc/rdoc/core/files/lib/core/facets/boolean_rb.html +2 -2
- data/doc/rdoc/core/files/lib/core/facets/class/methodize_rb.html +96 -0
- data/doc/rdoc/core/files/lib/core/facets/class/pathize_rb.html +96 -0
- data/doc/rdoc/core/files/lib/core/facets/class_rb.html +5 -1
- data/doc/rdoc/core/files/lib/core/facets/dir_rb.html +1 -1
- data/doc/rdoc/core/files/lib/core/facets/{class/to_methodname_rb.html → enumerable/commonality_rb.html} +4 -4
- data/doc/rdoc/core/files/lib/core/facets/enumerable/entropy_rb.html +96 -0
- data/doc/rdoc/core/files/lib/core/facets/{class/to_pathname_rb.html → enumerable/frequency_rb.html} +4 -4
- data/doc/rdoc/core/files/lib/core/facets/enumerable/probability_rb.html +1 -1
- data/doc/rdoc/core/files/lib/core/facets/enumerable_rb.html +6 -2
- data/doc/rdoc/core/files/lib/core/facets/file_rb.html +2 -1
- data/doc/rdoc/core/files/lib/core/facets/hash_rb.html +7 -1
- data/doc/rdoc/{more/files/lib/more → core/files/lib/core}/facets/indexable_rb.html +2 -2
- data/doc/rdoc/core/files/lib/core/facets/kernel/require_all_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/kernel/require_local_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/kernel_rb.html +15 -2
- data/doc/rdoc/core/files/lib/core/facets/module/integrate_rb.html +96 -0
- data/doc/rdoc/core/files/lib/core/facets/module/methodize_rb.html +96 -0
- data/doc/rdoc/core/files/lib/core/facets/module/module_load_rb.html +1 -1
- data/doc/rdoc/core/files/lib/core/facets/module/pathize_rb.html +5 -1
- data/doc/rdoc/core/files/lib/core/facets/module/redefine_method_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/module/redirect_method_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/module/rename_method_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/module/revise_rb.html +8 -1
- data/doc/rdoc/core/files/lib/core/facets/module/wrap_method_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/module_rb.html +8 -5
- data/doc/rdoc/core/files/lib/core/facets/numeric_rb.html +2 -1
- data/doc/rdoc/core/files/lib/core/facets/proc_rb.html +3 -5
- data/doc/rdoc/{more/files/lib/more → core/files/lib/core}/facets/stackable_rb.html +3 -4
- data/doc/rdoc/core/files/lib/core/facets/string/each_word_rb.html +96 -0
- data/doc/rdoc/core/files/lib/core/facets/{module/clone_rb.html → string/methodize_rb.html} +4 -4
- data/doc/rdoc/core/files/lib/core/facets/{kernel/load_rb.html → string/pathize_rb.html} +4 -4
- data/doc/rdoc/core/files/lib/core/facets/string/word_wrap_rb.html +92 -0
- data/doc/rdoc/core/files/lib/core/facets/string/words_rb.html +1 -5
- data/doc/rdoc/core/files/lib/core/facets/string_rb.html +8 -3
- data/doc/rdoc/core/files/lib/core/facets/symbol_rb.html +2 -1
- data/doc/rdoc/core/fr_class_index.html +2 -3
- data/doc/rdoc/core/fr_file_index.html +36 -16
- data/doc/rdoc/core/fr_method_index.html +778 -784
- data/doc/rdoc/lore/created.rid +1 -1
- data/doc/rdoc/more/classes/ANSICode.html +66 -66
- data/doc/rdoc/more/classes/Advisable.html +37 -37
- data/doc/rdoc/more/classes/Advisable/Method.html +20 -20
- data/doc/rdoc/more/classes/Archive/Tar/Minitar.html +27 -27
- data/doc/rdoc/more/classes/Archive/Tar/Minitar/Input.html +28 -28
- data/doc/rdoc/more/classes/Archive/Tar/Minitar/Output.html +19 -19
- data/doc/rdoc/more/classes/Archive/Tar/Minitar/Reader.html +31 -31
- data/doc/rdoc/more/classes/Archive/Tar/Minitar/Writer.html +33 -33
- data/doc/rdoc/more/classes/Association.html +28 -28
- data/doc/rdoc/more/classes/Association/Kernel.html +8 -8
- data/doc/rdoc/more/classes/Autoarray.html +12 -12
- data/doc/rdoc/more/classes/BBCode.html +34 -34
- data/doc/rdoc/more/classes/BaseX.html +16 -16
- data/doc/rdoc/more/classes/BiCrypt.html +67 -67
- data/doc/rdoc/more/classes/BigDuration.html +30 -30
- data/doc/rdoc/more/classes/BinReadable.html +85 -85
- data/doc/rdoc/more/classes/BinReadable/ByteOrder.html +25 -25
- data/doc/rdoc/more/classes/Binding.html +201 -0
- data/doc/rdoc/more/classes/Buildable.html +4 -4
- data/doc/rdoc/more/classes/BuildingBlock.html +32 -32
- data/doc/rdoc/more/classes/CLI.html +108 -0
- data/doc/rdoc/more/classes/CLI/Arguments.html +76 -76
- data/doc/rdoc/more/classes/CLI/Command.html +22 -22
- data/doc/rdoc/more/classes/CLI/NoCommandError.html +4 -4
- data/doc/rdoc/more/classes/CLI/NoOptionError.html +4 -4
- data/doc/rdoc/more/classes/CacheDecorator.html +21 -21
- data/doc/rdoc/more/classes/Capsule.html +41 -41
- data/doc/rdoc/more/classes/Chain.html +17 -17
- data/doc/rdoc/more/classes/Cloneable.html +4 -4
- data/doc/rdoc/more/classes/ConsoleUtils.html +18 -18
- data/doc/rdoc/more/classes/Coroutine.html +28 -28
- data/doc/rdoc/more/classes/Crypt.html +16 -16
- data/doc/rdoc/more/classes/CssFilter.html +45 -45
- data/doc/rdoc/more/classes/CssTree.html +8 -8
- data/doc/rdoc/more/classes/Dictionary.html +228 -228
- data/doc/rdoc/more/classes/DictionaryMatcher.html +38 -38
- data/doc/rdoc/more/classes/DictionaryMatcher/MatchData.html +4 -4
- data/doc/rdoc/more/classes/Downloader.html +56 -56
- data/doc/rdoc/more/classes/Duration.html +68 -68
- data/doc/rdoc/more/classes/Enumerable.html +44 -44
- data/doc/rdoc/more/classes/Enumerable/Elementor.html +16 -16
- data/doc/rdoc/more/classes/Enumerable/Enumerator.html +4 -4
- data/doc/rdoc/more/classes/EnumerablePass.html +15 -15
- data/doc/rdoc/more/classes/Equatable.html +16 -16
- data/doc/rdoc/more/classes/EventHook.html +8 -8
- data/doc/rdoc/more/classes/Expirable.html +17 -17
- data/doc/rdoc/more/classes/FileList.html +125 -125
- data/doc/rdoc/more/classes/FileShell.html +147 -147
- data/doc/rdoc/more/classes/Fileable.html +14 -14
- data/doc/rdoc/more/classes/Fileable/DSL.html +41 -41
- data/doc/rdoc/more/classes/Hash.html +306 -14
- data/doc/rdoc/more/classes/Hash2Xml.html +4 -4
- data/doc/rdoc/more/classes/HtmlFilter.html +9 -9
- data/doc/rdoc/more/classes/IORedirect.html +19 -19
- data/doc/rdoc/more/classes/InfinityClass.html +36 -36
- data/doc/rdoc/more/classes/InfinityClass/Numeric.html +23 -23
- data/doc/rdoc/more/classes/Ini.html +37 -37
- data/doc/rdoc/more/classes/Instantiable.html +9 -9
- data/doc/rdoc/more/classes/Instantise.html +8 -8
- data/doc/rdoc/more/classes/Interval.html +187 -187
- data/doc/rdoc/more/classes/It.html +12 -12
- data/doc/rdoc/more/classes/Kernel.html +77 -77
- data/doc/rdoc/more/classes/LRUCache.html +38 -38
- data/doc/rdoc/more/classes/LinkedList.html +68 -68
- data/doc/rdoc/more/classes/LinkedList/Node.html +4 -4
- data/doc/rdoc/{core → more}/classes/MissingArgument.html +1 -2
- data/doc/rdoc/more/classes/Module.html +171 -171
- data/doc/rdoc/more/classes/Multiton.html +12 -12
- data/doc/rdoc/more/classes/Multiton/MetaMethods.html +28 -28
- data/doc/rdoc/more/classes/Net/SMTP.html +19 -19
- data/doc/rdoc/more/classes/NullClass.html +24 -24
- data/doc/rdoc/more/classes/ObjectReflection.html +12 -12
- data/doc/rdoc/more/classes/OpEsc.html +5 -5
- data/doc/rdoc/more/classes/OpenCascade.html +4 -4
- data/doc/rdoc/more/classes/OpenCollection.html +8 -8
- data/doc/rdoc/more/classes/OpenHash.html +9 -9
- data/doc/rdoc/more/classes/OpenObject.html +95 -95
- data/doc/rdoc/more/classes/PQueue.html +84 -84
- data/doc/rdoc/more/classes/Paramix.html +11 -11
- data/doc/rdoc/more/classes/Paramix/Delegator.html +16 -16
- data/doc/rdoc/more/classes/PathList.html +8 -8
- data/doc/rdoc/more/classes/PathList/Finder.html +8 -8
- data/doc/rdoc/more/classes/Platform.html +46 -46
- data/doc/rdoc/more/classes/Pool.html +18 -18
- data/doc/rdoc/more/classes/Proc.html +48 -4
- data/doc/rdoc/more/classes/ProgressBar.html +52 -52
- data/doc/rdoc/more/classes/Prototype.html +28 -28
- data/doc/rdoc/more/classes/RWDelegator.html +16 -16
- data/doc/rdoc/more/classes/Random.html +9 -9
- data/doc/rdoc/more/classes/Random/Array.html +37 -37
- data/doc/rdoc/more/classes/Random/Hash.html +52 -52
- data/doc/rdoc/more/classes/Random/Object.html +4 -4
- data/doc/rdoc/more/classes/Random/String.html +34 -34
- data/doc/rdoc/more/classes/Random/String/Self.html +9 -9
- data/doc/rdoc/more/classes/Recorder.html +16 -16
- data/doc/rdoc/more/classes/Reference.html +19 -19
- data/doc/rdoc/more/classes/Registerable.html +13 -13
- data/doc/rdoc/more/classes/Semaphore.html +36 -36
- data/doc/rdoc/more/classes/Settings.html +28 -28
- data/doc/rdoc/more/classes/Settings/Setting.html +13 -13
- data/doc/rdoc/more/classes/Settings/SettingCollection.html +4 -4
- data/doc/rdoc/more/classes/SimpleStringIO.html +8 -8
- data/doc/rdoc/more/classes/Snapshot.html +16 -16
- data/doc/rdoc/more/classes/Snapshot/ValueHolder.html +12 -12
- data/doc/rdoc/more/classes/String/Style.html +113 -113
- data/doc/rdoc/{core → more}/classes/String/Words.html +78 -78
- data/doc/rdoc/more/classes/Struct.html +8 -8
- data/doc/rdoc/more/classes/SyncArray.html +4 -4
- data/doc/rdoc/more/classes/SyncHash.html +4 -4
- data/doc/rdoc/more/classes/SyncHash/Delegator.html +28 -28
- data/doc/rdoc/more/classes/SyncHash/Inheritor.html +28 -28
- data/doc/rdoc/more/classes/System.html +253 -253
- data/doc/rdoc/more/classes/Timer.html +48 -48
- data/doc/rdoc/more/classes/Timer/Dummy.html +9 -9
- data/doc/rdoc/more/classes/TracePoint.html +64 -62
- data/doc/rdoc/more/classes/Tuple.html +170 -170
- data/doc/rdoc/more/classes/TypeCast/Class.html +4 -4
- data/doc/rdoc/more/classes/TypeCast/Object.html +4 -4
- data/doc/rdoc/more/classes/Uninheritable.html +6 -6
- data/doc/rdoc/more/classes/UploadUtils.html +49 -49
- data/doc/rdoc/more/classes/VersionNumber.html +53 -53
- data/doc/rdoc/more/classes/Weekdays.html +28 -28
- data/doc/rdoc/more/classes/XOXO.html +9 -9
- data/doc/rdoc/more/classes/ZipUtils.html +58 -58
- data/doc/rdoc/more/classes/ZipUtils/DryRun.html +28 -28
- data/doc/rdoc/more/classes/ZipUtils/NoWrite.html +28 -28
- data/doc/rdoc/more/classes/ZipUtils/Verbose.html +28 -28
- data/doc/rdoc/more/created.rid +1 -1
- data/doc/rdoc/more/files/lib/more/facets/ansicode_rb.html +1 -1
- data/doc/rdoc/{core/files/lib/core → more/files/lib/more}/facets/binding/opvars_rb.html +2 -2
- data/doc/rdoc/{core/files/lib/core → more/files/lib/more}/facets/hash/stringify_keys_rb.html +2 -2
- data/doc/rdoc/{core/files/lib/core → more/files/lib/more}/facets/hash/symbolize_keys_rb.html +2 -2
- data/doc/rdoc/{core/files/lib/core/facets/proc → more/files/lib/more/facets}/partial_rb.html +8 -7
- data/doc/rdoc/more/files/lib/more/facets/snapshot_rb.html +2 -2
- data/doc/rdoc/more/files/lib/more/facets/string/words_rb.html +96 -0
- data/doc/rdoc/more/files/lib/more/facets/tracepoint_rb.html +13 -8
- data/doc/rdoc/more/fr_class_index.html +4 -2
- data/doc/rdoc/more/fr_file_index.html +9 -2
- data/doc/rdoc/more/fr_method_index.html +1013 -1009
- data/doc/ri/CLI/cdesc-CLI.yaml +7 -2
- data/doc/ri/Enumerable/probability-i.yaml +1 -1
- data/doc/ri/Module/append_features-i.yaml +4 -3
- data/doc/ri/Module/cdesc-Module.yaml +4 -3
- data/doc/ri/Module/methodize-i.yaml +14 -0
- data/doc/ri/Module/redefine_method-i.yaml +1 -1
- data/doc/ri/Module/redirect_method-i.yaml +3 -1
- data/doc/ri/Module/rename_method-i.yaml +1 -1
- data/doc/ri/created.rid +1 -1
- data/lib/core/facets/array.rb +3 -0
- data/lib/core/facets/binding.rb +0 -1
- data/lib/core/facets/class.rb +4 -4
- data/lib/core/facets/class/{to_methodname.rb → methodize.rb} +5 -2
- data/lib/core/facets/class/pathize.rb +14 -0
- data/lib/core/facets/enumerable.rb +5 -2
- data/lib/core/facets/enumerable/commonality.rb +33 -0
- data/lib/core/facets/enumerable/entropy.rb +37 -0
- data/lib/core/facets/enumerable/frequency.rb +18 -0
- data/lib/core/facets/enumerable/probability.rb +1 -98
- data/lib/core/facets/file.rb +1 -1
- data/lib/core/facets/hash.rb +6 -0
- data/lib/{more → core}/facets/indexable.rb +0 -0
- data/lib/core/facets/kernel.rb +15 -1
- data/lib/core/facets/kernel/require_all.rb +21 -0
- data/lib/core/facets/kernel/{load.rb → require_local.rb} +6 -23
- data/lib/core/facets/module.rb +7 -3
- data/lib/core/facets/module/integrate.rb +2 -0
- data/lib/core/facets/module/methodize.rb +14 -0
- data/lib/core/facets/module/pathize.rb +10 -7
- data/lib/core/facets/module/redefine_method.rb +35 -0
- data/lib/core/facets/module/redirect_method.rb +45 -0
- data/lib/core/facets/module/rename_method.rb +20 -0
- data/lib/core/facets/module/revise.rb +7 -113
- data/lib/core/facets/module/wrap_method.rb +28 -0
- data/lib/core/facets/numeric.rb +1 -1
- data/lib/core/facets/proc.rb +2 -3
- data/lib/{more → core}/facets/stackable.rb +0 -0
- data/lib/core/facets/string.rb +8 -6
- data/lib/core/facets/string/each_word.rb +13 -0
- data/lib/core/facets/string/methodize.rb +12 -0
- data/lib/core/facets/string/pathize.rb +12 -0
- data/lib/core/facets/string/word_wrap.rb +34 -0
- data/lib/core/facets/string/words.rb +6 -167
- data/lib/core/facets/symbol.rb +1 -0
- data/lib/more/facets/ansicode.rb +4 -4
- data/lib/{core → more}/facets/binding/opvars.rb +0 -0
- data/lib/{core → more}/facets/hash/stringify_keys.rb +0 -0
- data/lib/{core → more}/facets/hash/symbolize_keys.rb +5 -6
- data/lib/{core/facets/proc → more/facets}/partial.rb +0 -0
- data/lib/more/facets/string/words.rb +173 -0
- data/test/core/dir/test_multiglob.rb +1 -0
- data/test/core/dir/test_recurse.rb +1 -0
- data/test/core/enumerable/test_commonality.rb +15 -0
- data/test/core/enumerable/test_entropy.rb +15 -0
- data/test/core/enumerable/test_frequency.rb +11 -0
- data/test/core/enumerable/test_probability.rb +1 -34
- data/test/core/string/test_each_word.rb +14 -0
- data/test/core/string/test_fold.rb +1 -1
- data/test/core/string/test_word_wrap.rb +35 -0
- data/test/core/string/test_words.rb +12 -61
- data/test/more/test_command.rb +7 -9
- data/test/more/test_paramix.rb +4 -1
- data/test/{core/proc → more}/test_partial.rb +1 -1
- metadata +75 -38
- data/doc/rdoc/core/classes/Module/CloneExtensions.html +0 -287
- data/doc/ri/Module/CloneExtensions/cdesc-CloneExtensions.yaml +0 -20
- data/doc/ri/Module/CloneExtensions/clone_removing-i.yaml +0 -14
- data/doc/ri/Module/CloneExtensions/clone_renaming-i.yaml +0 -14
- data/doc/ri/Module/CloneExtensions/clone_using-i.yaml +0 -14
- data/lib/core/facets/class/to_pathname.rb +0 -12
- data/lib/core/facets/module/clone.rb +0 -57
- data/test/core/module/test_clone.rb +0 -45
data/lib/core/facets/numeric.rb
CHANGED
data/lib/core/facets/proc.rb
CHANGED
File without changes
|
data/lib/core/facets/string.rb
CHANGED
@@ -5,12 +5,15 @@ require 'facets/string/capitalized.rb'
|
|
5
5
|
require 'facets/string/chomp.rb'
|
6
6
|
require 'facets/string/cleave.rb'
|
7
7
|
require 'facets/string/divide.rb'
|
8
|
+
require 'facets/string/each_word.rb'
|
8
9
|
require 'facets/string/fold.rb'
|
9
10
|
require 'facets/string/interpolate.rb'
|
10
11
|
require 'facets/string/line_wrap.rb'
|
12
|
+
require 'facets/string/methodize.rb'
|
11
13
|
require 'facets/string/mscan.rb'
|
12
14
|
require 'facets/string/natcmp.rb'
|
13
15
|
require 'facets/string/nchar.rb'
|
16
|
+
require 'facets/string/pathize.rb'
|
14
17
|
require 'facets/string/range.rb'
|
15
18
|
require 'facets/string/rewrite.rb'
|
16
19
|
require 'facets/string/shatter.rb'
|
@@ -20,16 +23,15 @@ require 'facets/string/subtract.rb'
|
|
20
23
|
require 'facets/string/tab.rb'
|
21
24
|
require 'facets/string/titlecase.rb'
|
22
25
|
require 'facets/string/to_re.rb'
|
23
|
-
|
24
|
-
|
26
|
+
require 'facets/string/to_time.rb'
|
27
|
+
require 'facets/string/words.rb'
|
25
28
|
require 'facets/string/xor.rb'
|
26
29
|
|
27
|
-
|
28
|
-
require 'facets/string/end_with.rb'
|
29
|
-
|
30
|
+
# 1.9
|
30
31
|
require 'facets/string/bytes.rb'
|
31
32
|
require 'facets/string/chars.rb'
|
32
33
|
require 'facets/string/lines.rb'
|
33
|
-
|
34
|
+
require 'facets/string/start_with.rb'
|
35
|
+
require 'facets/string/end_with.rb'
|
34
36
|
require 'facets/string/each_char.rb'
|
35
37
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
# Translate a (class or module) name to a suitable method name.
|
4
|
+
#
|
5
|
+
# My::CoolClass.name.methodize => "my__cool_class"
|
6
|
+
#
|
7
|
+
def methodize
|
8
|
+
gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').gsub('::','__').downcase
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
# Word wrap a string not exceeding max width.
|
4
|
+
#
|
5
|
+
# puts "this is a test".word_wrap(4)
|
6
|
+
#
|
7
|
+
# _produces_
|
8
|
+
#
|
9
|
+
# this
|
10
|
+
# is a
|
11
|
+
# test
|
12
|
+
#
|
13
|
+
# This is basic implementation of word wrap, but smart
|
14
|
+
# enough to suffice for most use cases.
|
15
|
+
#
|
16
|
+
# CREDIT: Gavin Kistner
|
17
|
+
# CREDIT: Dayne Broderson
|
18
|
+
#
|
19
|
+
def word_wrap( col_width=80 )
|
20
|
+
self.dup.word_wrap!( col_width )
|
21
|
+
end
|
22
|
+
|
23
|
+
# As with #word_wrap, but modifies the string in place.
|
24
|
+
#
|
25
|
+
# CREDIT: Gavin Kistner
|
26
|
+
# CREDIT: Dayne Broderson
|
27
|
+
#
|
28
|
+
def word_wrap!( col_width=80 )
|
29
|
+
self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
|
30
|
+
self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -1,173 +1,12 @@
|
|
1
|
-
require 'facets/string/fold'
|
2
|
-
|
3
1
|
class String
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def words
|
12
|
-
self.split(/\s+/)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Iterate through each word of a string.
|
16
|
-
#
|
17
|
-
# "a string".each_word { |word, range| ... }
|
18
|
-
|
19
|
-
def each_word( &yld )
|
20
|
-
rest_of_string = self
|
21
|
-
wordfind = /([-'\w]+)/
|
22
|
-
arity = yld.arity
|
23
|
-
offset = 0
|
24
|
-
while wmatch = wordfind.match(rest_of_string)
|
25
|
-
word = wmatch[0]
|
26
|
-
range = offset+wmatch.begin(0) ... offset+wmatch.end(0)
|
27
|
-
rest_of_string = wmatch.post_match
|
28
|
-
if arity == 1
|
29
|
-
yld.call(word)
|
30
|
-
else
|
31
|
-
yld.call(word, range)
|
32
|
-
end
|
33
|
-
offset = self.length - rest_of_string.length
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Filters out words from a string based on block test.
|
38
|
-
#
|
39
|
-
# "a string".word_filter { |word| word =~ /^a/ } #=> "string"
|
40
|
-
#
|
41
|
-
# CREDIT: George Moschovitis
|
42
|
-
|
43
|
-
def word_filter( &blk )
|
44
|
-
s = self.dup
|
45
|
-
s.word_filter!( &blk )
|
46
|
-
end
|
47
|
-
|
48
|
-
# In place version of #word_filter.
|
49
|
-
#
|
50
|
-
# "a string".word_filter { |word| ... }
|
51
|
-
#
|
52
|
-
# CREDIT: George Moschovitis
|
53
|
-
|
54
|
-
def word_filter! #:yield:
|
55
|
-
rest_of_string = self
|
56
|
-
wordfind = /(\w+)/
|
57
|
-
offset = 0
|
58
|
-
while wmatch = wordfind.match(rest_of_string)
|
59
|
-
word = wmatch[0]
|
60
|
-
range = offset+wmatch.begin(0) ... offset+wmatch.end(0)
|
61
|
-
rest_of_string = wmatch.post_match
|
62
|
-
self[range] = yield( word ).to_s
|
63
|
-
offset = self.length - rest_of_string.length
|
64
|
-
end
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
# TODO: This is alternateive from glue: worth providing?
|
69
|
-
#
|
70
|
-
# Enforces a maximum width of a string inside an
|
71
|
-
# html container. If the string exceeds this maximum width
|
72
|
-
# the string gets wraped.
|
73
|
-
#
|
74
|
-
# Not really useful, better use the CSS overflow: hidden
|
75
|
-
# functionality.
|
76
|
-
#
|
77
|
-
# === Input:
|
78
|
-
# the string to be wrapped
|
79
|
-
# the enforced width
|
80
|
-
# the separator used for wrapping
|
81
|
-
#
|
82
|
-
# === Output:
|
83
|
-
# the wrapped string
|
84
|
-
#
|
85
|
-
# === Example:
|
86
|
-
# text = "1111111111111111111111111111111111111111111"
|
87
|
-
# text = wrap(text, 10, " ")
|
88
|
-
# p text # => "1111111111 1111111111 1111111111"
|
89
|
-
#
|
90
|
-
# See the test cases to better understand the behaviour!
|
91
|
-
|
92
|
-
# def wrap(width = 20, separator = " ")
|
93
|
-
# re = /([^#{separator}]{1,#{width}})/
|
94
|
-
# scan(re).join(separator)
|
95
|
-
# end
|
96
|
-
|
97
|
-
# Word wrap a string not exceeding max width.
|
98
|
-
#
|
99
|
-
# puts "this is a test".word_wrap(4)
|
100
|
-
#
|
101
|
-
# _produces_
|
102
|
-
#
|
103
|
-
# this
|
104
|
-
# is a
|
105
|
-
# test
|
106
|
-
#
|
107
|
-
# CREDIT: Gavin Kistner
|
108
|
-
# CREDIT: Dayne Broderson
|
109
|
-
|
110
|
-
def word_wrap( col_width=80 )
|
111
|
-
self.dup.word_wrap!( col_width )
|
112
|
-
end
|
113
|
-
|
114
|
-
# As with #word_wrap, but modifies the string in place.
|
115
|
-
#
|
116
|
-
# CREDIT: Gavin Kistner
|
117
|
-
# CREDIT: Dayne Broderson
|
118
|
-
|
119
|
-
def word_wrap!( col_width=80 )
|
120
|
-
self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
|
121
|
-
self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
|
122
|
-
self
|
123
|
-
end
|
124
|
-
|
125
|
-
# old def
|
126
|
-
|
127
|
-
#def word_wrap(max=80)
|
128
|
-
# c = dup
|
129
|
-
# c.word_wrap!(max)
|
130
|
-
# c
|
131
|
-
#end
|
132
|
-
|
133
|
-
#def word_wrap!(max=80)
|
134
|
-
# raise ArgumentError, "Wrap margin too low: #{n}" if max <= 2
|
135
|
-
# #gsub!( Regexp.new( "(.{1,#{max-1}}\\w)\\b\\s*" ), "\\1\n")
|
136
|
-
# gsub!( /(.{1,#{max-1}}\S)([ ]|\n)/, "\\1\n")
|
137
|
-
#end
|
138
|
-
|
139
|
-
# Returns short abstract of long strings; not exceeding +range+
|
140
|
-
# characters. If range is an integer then the minimum is 20%
|
141
|
-
# of the maximum. The string is chopped at the nearest word
|
142
|
-
# if possible, and appended by +ellipsis+, which defaults
|
143
|
-
# to '...'.
|
144
|
-
#
|
145
|
-
# CREDIT: George Moschovitis
|
146
|
-
# CREDIT: Trans
|
147
|
-
|
148
|
-
def brief(range=76, ellipsis="...")
|
149
|
-
if Range===range
|
150
|
-
min = range.first
|
151
|
-
max = range.last
|
152
|
-
else
|
153
|
-
max = range
|
154
|
-
min = max - (max/5).to_i
|
155
|
-
range = min..max
|
156
|
-
end
|
157
|
-
|
158
|
-
if size > max
|
159
|
-
cut_at = rindex(/\b/, max) || max
|
160
|
-
cut_at = max if cut_at < min
|
161
|
-
xstring = slice(0, cut_at)
|
162
|
-
xstring.chomp(" ") + ellipsis
|
163
|
-
else
|
164
|
-
self
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
3
|
+
# Returns an array of characters.
|
4
|
+
#
|
5
|
+
# "abc 123".words #=> ["abc","123"]
|
6
|
+
#
|
7
|
+
def words
|
8
|
+
self.split(/\s+/)
|
168
9
|
end
|
169
10
|
|
170
|
-
include Words
|
171
|
-
|
172
11
|
end
|
173
12
|
|
data/lib/core/facets/symbol.rb
CHANGED
data/lib/more/facets/ansicode.rb
CHANGED
File without changes
|
File without changes
|
@@ -19,7 +19,7 @@ class Hash
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
alias_method( :keys_to_sym, :symbolize_keys )
|
22
|
+
#alias_method( :keys_to_sym, :symbolize_keys )
|
23
23
|
|
24
24
|
#--
|
25
25
|
# # Rails has these aliases too, but they are not very good for
|
@@ -45,7 +45,7 @@ class Hash
|
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
|
-
alias_method( :keys_to_sym!, :symbolize_keys! )
|
48
|
+
#alias_method( :keys_to_sym!, :symbolize_keys! )
|
49
49
|
|
50
50
|
# Converts all keys in the Hash to Strings, returning a new Hash.
|
51
51
|
# With a +filter+ parameter, limits conversion to only a certain selection of keys.
|
@@ -64,7 +64,7 @@ class Hash
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
alias_method(:keys_to_s, :stringify_keys)
|
67
|
+
#alias_method(:keys_to_s, :stringify_keys)
|
68
68
|
|
69
69
|
# Synonym for Hash#stringify_keys, but modifies the receiver in place and returns it.
|
70
70
|
# With a +filter+ parameter, limits conversion to only a certain selection of keys.
|
@@ -83,11 +83,10 @@ class Hash
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
alias_method( :keys_to_s!, :stringify_keys!)
|
86
|
+
#alias_method( :keys_to_s!, :stringify_keys!)
|
87
87
|
|
88
88
|
#--
|
89
|
-
# # Rails has these aliases too
|
90
|
-
# # gerenal use, IMHO. But perhaps someone can convince me otherwise.
|
89
|
+
# # Rails has these aliases too.
|
91
90
|
# alias_method( :to_options!, :symbolize_keys! )
|
92
91
|
#++
|
93
92
|
|
File without changes
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'facets/string/fold'
|
2
|
+
|
3
|
+
class String
|
4
|
+
|
5
|
+
module Words
|
6
|
+
|
7
|
+
# Returns an array of characters.
|
8
|
+
#
|
9
|
+
# "abc 123".words #=> ["abc","123"]
|
10
|
+
|
11
|
+
def words
|
12
|
+
self.split(/\s+/)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Iterate through each word of a string.
|
16
|
+
#
|
17
|
+
# "a string".each_word { |word, range| ... }
|
18
|
+
|
19
|
+
def each_word( &yld )
|
20
|
+
rest_of_string = self
|
21
|
+
wordfind = /([-'\w]+)/
|
22
|
+
arity = yld.arity
|
23
|
+
offset = 0
|
24
|
+
while wmatch = wordfind.match(rest_of_string)
|
25
|
+
word = wmatch[0]
|
26
|
+
range = offset+wmatch.begin(0) ... offset+wmatch.end(0)
|
27
|
+
rest_of_string = wmatch.post_match
|
28
|
+
if arity == 1
|
29
|
+
yld.call(word)
|
30
|
+
else
|
31
|
+
yld.call(word, range)
|
32
|
+
end
|
33
|
+
offset = self.length - rest_of_string.length
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Filters out words from a string based on block test.
|
38
|
+
#
|
39
|
+
# "a string".word_filter { |word| word =~ /^a/ } #=> "string"
|
40
|
+
#
|
41
|
+
# CREDIT: George Moschovitis
|
42
|
+
|
43
|
+
def word_filter( &blk )
|
44
|
+
s = self.dup
|
45
|
+
s.word_filter!( &blk )
|
46
|
+
end
|
47
|
+
|
48
|
+
# In place version of #word_filter.
|
49
|
+
#
|
50
|
+
# "a string".word_filter { |word| ... }
|
51
|
+
#
|
52
|
+
# CREDIT: George Moschovitis
|
53
|
+
|
54
|
+
def word_filter! #:yield:
|
55
|
+
rest_of_string = self
|
56
|
+
wordfind = /(\w+)/
|
57
|
+
offset = 0
|
58
|
+
while wmatch = wordfind.match(rest_of_string)
|
59
|
+
word = wmatch[0]
|
60
|
+
range = offset+wmatch.begin(0) ... offset+wmatch.end(0)
|
61
|
+
rest_of_string = wmatch.post_match
|
62
|
+
self[range] = yield( word ).to_s
|
63
|
+
offset = self.length - rest_of_string.length
|
64
|
+
end
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
# TODO: This is alternateive from glue: worth providing?
|
69
|
+
#
|
70
|
+
# Enforces a maximum width of a string inside an
|
71
|
+
# html container. If the string exceeds this maximum width
|
72
|
+
# the string gets wraped.
|
73
|
+
#
|
74
|
+
# Not really useful, better use the CSS overflow: hidden
|
75
|
+
# functionality.
|
76
|
+
#
|
77
|
+
# === Input:
|
78
|
+
# the string to be wrapped
|
79
|
+
# the enforced width
|
80
|
+
# the separator used for wrapping
|
81
|
+
#
|
82
|
+
# === Output:
|
83
|
+
# the wrapped string
|
84
|
+
#
|
85
|
+
# === Example:
|
86
|
+
# text = "1111111111111111111111111111111111111111111"
|
87
|
+
# text = wrap(text, 10, " ")
|
88
|
+
# p text # => "1111111111 1111111111 1111111111"
|
89
|
+
#
|
90
|
+
# See the test cases to better understand the behaviour!
|
91
|
+
|
92
|
+
# def wrap(width = 20, separator = " ")
|
93
|
+
# re = /([^#{separator}]{1,#{width}})/
|
94
|
+
# scan(re).join(separator)
|
95
|
+
# end
|
96
|
+
|
97
|
+
# Word wrap a string not exceeding max width.
|
98
|
+
#
|
99
|
+
# puts "this is a test".word_wrap(4)
|
100
|
+
#
|
101
|
+
# _produces_
|
102
|
+
#
|
103
|
+
# this
|
104
|
+
# is a
|
105
|
+
# test
|
106
|
+
#
|
107
|
+
# CREDIT: Gavin Kistner
|
108
|
+
# CREDIT: Dayne Broderson
|
109
|
+
|
110
|
+
def word_wrap( col_width=80 )
|
111
|
+
self.dup.word_wrap!( col_width )
|
112
|
+
end
|
113
|
+
|
114
|
+
# As with #word_wrap, but modifies the string in place.
|
115
|
+
#
|
116
|
+
# CREDIT: Gavin Kistner
|
117
|
+
# CREDIT: Dayne Broderson
|
118
|
+
|
119
|
+
def word_wrap!( col_width=80 )
|
120
|
+
self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
|
121
|
+
self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
# old def
|
126
|
+
|
127
|
+
#def word_wrap(max=80)
|
128
|
+
# c = dup
|
129
|
+
# c.word_wrap!(max)
|
130
|
+
# c
|
131
|
+
#end
|
132
|
+
|
133
|
+
#def word_wrap!(max=80)
|
134
|
+
# raise ArgumentError, "Wrap margin too low: #{n}" if max <= 2
|
135
|
+
# #gsub!( Regexp.new( "(.{1,#{max-1}}\\w)\\b\\s*" ), "\\1\n")
|
136
|
+
# gsub!( /(.{1,#{max-1}}\S)([ ]|\n)/, "\\1\n")
|
137
|
+
#end
|
138
|
+
|
139
|
+
# Returns short abstract of long strings; not exceeding +range+
|
140
|
+
# characters. If range is an integer then the minimum is 20%
|
141
|
+
# of the maximum. The string is chopped at the nearest word
|
142
|
+
# if possible, and appended by +ellipsis+, which defaults
|
143
|
+
# to '...'.
|
144
|
+
#
|
145
|
+
# CREDIT: George Moschovitis
|
146
|
+
# CREDIT: Trans
|
147
|
+
|
148
|
+
def brief(range=76, ellipsis="...")
|
149
|
+
if Range===range
|
150
|
+
min = range.first
|
151
|
+
max = range.last
|
152
|
+
else
|
153
|
+
max = range
|
154
|
+
min = max - (max/5).to_i
|
155
|
+
range = min..max
|
156
|
+
end
|
157
|
+
|
158
|
+
if size > max
|
159
|
+
cut_at = rindex(/\b/, max) || max
|
160
|
+
cut_at = max if cut_at < min
|
161
|
+
xstring = slice(0, cut_at)
|
162
|
+
xstring.chomp(" ") + ellipsis
|
163
|
+
else
|
164
|
+
self
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
include Words
|
171
|
+
|
172
|
+
end
|
173
|
+
|