facets 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.index +11 -7
- data/CONTRIBUTING.md +112 -0
- data/HISTORY.md +38 -0
- data/{README.rdoc → README.md} +59 -59
- data/demo/core/array/after.md +13 -0
- data/demo/core/array/arrange.md +17 -0
- data/demo/core/array/before.md +14 -0
- data/demo/core/array/collapse.md +15 -0
- data/demo/core/array/collisions.md +30 -0
- data/demo/core/array/commonality.md +31 -0
- data/demo/core/array/conjoin.md +47 -0
- data/demo/core/array/contains.md +9 -0
- data/demo/core/array/delete_unless.md +13 -0
- data/demo/core/array/delete_values.md +10 -0
- data/demo/core/array/delete_values_at.md +15 -0
- data/demo/core/array/divide.md +14 -0
- data/demo/core/array/duplicates.md +14 -0
- data/demo/core/array/each_overlap.md +12 -0
- data/demo/core/array/each_pair.md +13 -0
- data/demo/core/array/each_value.md +12 -0
- data/demo/core/array/entropy.md +13 -0
- data/demo/core/array/extract_options.md +13 -0
- data/demo/core/array/first.md +11 -0
- data/demo/core/array/from.md +11 -0
- data/demo/core/array/ideal_entropy.md +11 -0
- data/demo/core/array/intersection.md +11 -0
- data/demo/core/array/last.md +11 -0
- data/demo/core/array/median.md +23 -0
- data/demo/core/array/merge.md +15 -0
- data/demo/core/array/missing.md +10 -0
- data/demo/core/array/mode.md +9 -0
- data/demo/core/array/nonuniq.md +16 -0
- data/demo/core/array/not_empty.md +8 -0
- data/demo/core/array/occur.md +18 -0
- data/demo/core/array/occurrence.md +13 -0
- data/demo/core/array/only.md +9 -0
- data/demo/core/array/op_pow.md +10 -0
- data/demo/core/array/pad.md +28 -0
- data/demo/core/array/peek.md +10 -0
- data/demo/core/array/poke.md +15 -0
- data/demo/core/array/probability +8 -0
- data/demo/core/array/pull.md +10 -0
- data/demo/core/array/recurse.md +10 -0
- data/demo/core/array/recursively.md +20 -0
- data/demo/core/array/reject_values.md +10 -0
- data/demo/core/array/splice.md +14 -0
- data/demo/core/array/split.md +13 -0
- data/demo/core/array/squeeze.md +14 -0
- data/demo/core/array/step.md +16 -0
- data/demo/core/array/store.md +9 -0
- data/demo/core/array/thru.md +12 -0
- data/demo/core/array/to_h.md +11 -0
- data/demo/core/array/traverse.md +20 -0
- data/demo/core/array/uniq_by.md +16 -0
- data/demo/core/array/unique_permutation.md +14 -0
- data/demo/core/array/zip.md +8 -0
- data/demo/core/binding/caller.md +57 -0
- data/demo/core/binding/defined.md +10 -0
- data/demo/core/binding/opvars.md +16 -0
- data/demo/core/binding/self.md +6 -0
- data/demo/core/class/descendants.md +13 -0
- data/demo/core/class/to_proc.md +11 -0
- data/demo/core/comparable/at_least.md +11 -0
- data/demo/core/comparable/at_most.md +11 -0
- data/demo/core/comparable/bound.md +13 -0
- data/demo/core/comparable/cap.md +11 -0
- data/demo/core/comparable/clip.md +29 -0
- data/demo/core/comparable/cmp.md +18 -0
- data/demo/core/comparable/op_get.md +32 -0
- data/demo/core/dir/ascend.md +24 -0
- data/demo/core/dir/descend.md +16 -0
- data/demo/core/dir/multiglob.md +41 -0
- data/demo/core/dir/parent.md +6 -0
- data/demo/core/dir/recurse.md +41 -0
- data/demo/core/exception/detail.md +19 -0
- data/demo/core/{facets.rdoc → facets.md} +1 -1
- data/demo/core/filetest/root.md +13 -0
- data/demo/core/hash/recursively.md +21 -0
- data/demo/core/indexable.md +95 -0
- data/demo/core/integer/bitmask.md +46 -0
- data/demo/core/integer/{factorial.rdoc → factorial.md} +1 -1
- data/demo/core/integer/{length.rdoc → length.md} +1 -1
- data/demo/core/integer/{multiple.rdoc → multiple.md} +3 -1
- data/demo/core/integer/of.md +11 -0
- data/demo/core/integer/{ordinal.rdoc → ordinal.md} +3 -1
- data/demo/core/integer/{of.rdoc → times_collect.md} +2 -7
- data/demo/core/matchdata/match.md +7 -0
- data/demo/core/matchdata/matchset.md +7 -0
- data/demo/core/matchdata/matchtree.md +10 -0
- data/demo/core/module/cattr.md +43 -0
- data/demo/core/module/class_extend.md +64 -0
- data/demo/core/module/{class_inheritor.rdoc → class_inheritor.md} +2 -2
- data/demo/core/module/{copy_inheritor.rdoc → copy_inheritor.md} +4 -4
- data/demo/core/module/include_as.md +31 -0
- data/demo/core/module/method_space.md +24 -0
- data/demo/core/string/acronym.md +9 -0
- data/demo/core/string/{align.rdoc → align.md} +10 -10
- data/demo/core/string/ascii_only.md +37 -0
- data/demo/core/string/{bracket.rdoc → bracket.md} +10 -10
- data/demo/core/string/camelcase.md +47 -0
- data/demo/core/string/{capitalized.rdoc → capitalized.md} +9 -9
- data/demo/core/string/characters.md +11 -0
- data/demo/core/string/{cleanlines.rdoc → cleanlines.md} +3 -3
- data/demo/core/string/cleave.md +49 -0
- data/demo/core/string/compress_lines.md +22 -0
- data/demo/core/string/crypt.md +15 -0
- data/demo/core/string/divide.md +9 -0
- data/demo/core/string/each_word.md +11 -0
- data/demo/core/string/edit_distance.md +15 -0
- data/demo/core/string/exclude.md +15 -0
- data/demo/core/string/expand_tabs.md +69 -0
- data/demo/core/string/fold.md +14 -0
- data/demo/core/string/indent.md +65 -0
- data/demo/core/string/index_all.md +14 -0
- data/demo/core/string/interpolate.md +8 -0
- data/demo/core/string/lchomp.md +14 -0
- data/demo/core/string/line_wrap.md +7 -0
- data/demo/core/string/lowercase.md +12 -0
- data/demo/core/string/methodize.md +22 -0
- data/demo/core/string/modulize.md +22 -0
- data/demo/core/string/mscan.md +10 -0
- data/demo/core/string/natcmp.md +10 -0
- data/demo/core/string/nchar.md +9 -0
- data/demo/core/string/{newlines.rdoc → newlines.md} +3 -3
- data/demo/core/string/number.md +27 -0
- data/demo/core/string/op_div.md +10 -0
- data/demo/core/string/op_sub.md +7 -0
- data/demo/core/string/pathize.md +22 -0
- data/demo/core/string/quote.md +20 -0
- data/demo/core/string/random.md +25 -0
- data/demo/core/string/range.md +19 -0
- data/demo/core/string/remove.md +33 -0
- data/demo/core/string/rewrite.md +9 -0
- data/demo/core/string/shatter.md +9 -0
- data/demo/core/string/similarity.md +12 -0
- data/demo/core/string/snakecase.md +14 -0
- data/demo/core/string/splice.md +28 -0
- data/demo/core/string/squish.md +27 -0
- data/demo/core/string/store.md +10 -0
- data/demo/core/string/subtract.md +8 -0
- data/demo/core/string/titlecase.md +8 -0
- data/demo/core/string/to_re.md +22 -0
- data/demo/core/string/{margin.rdoc → trim.md} +14 -14
- data/demo/core/string/unbracket.md +24 -0
- data/demo/core/string/underscore.md +17 -0
- data/demo/core/string/unfold.md +9 -0
- data/demo/core/string/unindent.md +65 -0
- data/demo/core/string/unquote.md +6 -0
- data/demo/core/string/uppercase.md +15 -0
- data/demo/core/string/variablize.md +7 -0
- data/demo/core/string/word_wrap.md +54 -0
- data/demo/core/string/words.md +13 -0
- data/demo/core/string/xor.md +8 -0
- data/lib/core/facets.yml +11 -7
- data/lib/core/facets/array.rb +1 -0
- data/lib/core/facets/array/average.rb +16 -0
- data/lib/core/facets/array/collapse.rb +4 -0
- data/lib/core/facets/array/delete_values_at.rb +1 -0
- data/lib/core/facets/array/divide.rb +7 -0
- data/lib/core/facets/array/duplicates.rb +2 -0
- data/lib/core/facets/array/each_pair.rb +1 -4
- data/lib/core/facets/array/first.rb +1 -0
- data/lib/core/facets/array/from.rb +11 -16
- data/lib/core/facets/array/intersection.rb +1 -1
- data/lib/core/facets/array/last.rb +1 -0
- data/lib/core/facets/array/mode.rb +2 -2
- data/lib/core/facets/array/occurrence.rb +4 -3
- data/lib/core/facets/array/op_pow.rb +0 -2
- data/lib/core/facets/array/probability.rb +1 -1
- data/lib/core/facets/array/recursively.rb +2 -2
- data/lib/core/facets/array/splice.rb +1 -1
- data/lib/core/facets/array/standard_deviation.rb +23 -0
- data/lib/core/facets/array/to_h.rb +0 -3
- data/lib/core/facets/array/uniq_by.rb +4 -0
- data/lib/core/facets/array/variance.rb +20 -0
- data/lib/core/facets/binding.rb +0 -1
- data/lib/core/facets/enumerable/cluster.rb +6 -4
- data/lib/core/facets/enumerable/hashify.rb +27 -31
- data/lib/core/facets/enumerable/sum.rb +12 -2
- data/lib/core/facets/file/atomic_open.rb +1 -1
- data/lib/core/facets/hash/except.rb +13 -1
- data/lib/core/facets/indexable.rb +1 -1
- data/lib/core/facets/kernel/ergo.rb +3 -3
- data/lib/core/facets/kernel/like.rb +1 -1
- data/lib/core/facets/matchdata/matchtree.rb +2 -0
- data/lib/core/facets/numeric/delimit.rb +20 -0
- data/lib/core/facets/range/nudge.rb +29 -0
- data/lib/core/facets/string.rb +0 -2
- data/lib/core/facets/string/indent.rb +0 -8
- data/lib/core/facets/string/margin.rb +0 -4
- data/lib/core/facets/string/random.rb +13 -3
- data/lib/core/facets/string/similarity.rb +7 -6
- data/lib/standard/facets/enumargs.rb +5 -0
- data/lib/standard/facets/math/percentile.rb +1 -1
- data/lib/standard/facets/net/http.rb +33 -14
- data/lib/standard/facets/timer.rb +3 -3
- data/test/core/array/test_average.rb +16 -0
- data/test/core/array/test_before.rb +21 -0
- data/test/core/array/test_collapse.rb +10 -1
- data/test/core/array/test_delete_unless.rb +17 -0
- data/test/core/array/test_delete_values.rb +31 -0
- data/test/core/array/test_divide.rb +10 -0
- data/test/core/array/test_each_pair.rb +16 -0
- data/test/core/array/test_each_value.rb +16 -0
- data/test/core/array/test_from.rb +42 -0
- data/test/core/array/test_op_pow.rb +13 -0
- data/test/core/array/test_standard_deviation.rb +18 -0
- data/test/core/array/test_to_h.rb +14 -0
- data/test/core/array/test_uniq_by.rb +7 -0
- data/test/core/array/test_variance.rb +17 -0
- data/test/core/array/test_zip.rb +13 -0
- data/test/core/dir/test_each_child.rb +1 -1
- data/test/core/dir/test_multiglob.rb +1 -1
- data/test/core/enumerable/test_cluster.rb +36 -0
- data/test/core/enumerable/test_hashify.rb +113 -0
- data/test/core/hash/test_expect.rb +11 -1
- data/test/core/kernel/test_ergo.rb +7 -5
- data/test/core/{object/test_replace.rb → kernel/test_instance_replace.rb} +6 -28
- data/test/core/numeric/test_delimit.rb +68 -0
- data/test/core/numeric/{test_round.rb → test_round_to.rb} +27 -27
- data/test/core/range/test_nudge.rb +32 -0
- data/test/core/range/{test_to_r.rb → test_to_rng.rb} +3 -3
- data/test/core/string/test_acronym.rb +14 -0
- data/test/core/string/test_ascii_only.rb +21 -0
- data/test/core/string/test_compress_lines.rb +9 -0
- data/test/core/string/test_crypt.rb +17 -0
- data/test/core/string/test_index_all.rb +4 -0
- data/test/core/string/test_random.rb +25 -0
- data/test/core/string/test_remove.rb +14 -0
- data/test/core/string/test_similarity.rb +9 -1
- data/test/core/struct/test_replace.rb +18 -0
- data/test/standard/test_enumargs.rb +26 -10
- data/test/standard/test_timer.rb +1 -1
- metadata +634 -588
- data/CONTRIBUTE.md +0 -78
- data/demo/core/array/combination.rdoc +0 -19
- data/demo/core/array/delete.rdoc +0 -23
- data/demo/core/array/index.rdoc +0 -14
- data/demo/core/array/merge.rdoc +0 -15
- data/demo/core/array/only.rdoc +0 -9
- data/demo/core/array/pad.rdoc +0 -28
- data/demo/core/array/permutation.rdoc +0 -10
- data/demo/core/array/product.rdoc +0 -26
- data/demo/core/array/recursively.rdoc +0 -16
- data/demo/core/array/rotate.rdoc +0 -30
- data/demo/core/array/select.rdoc +0 -8
- data/demo/core/array/uniq_by.rdoc +0 -9
- data/demo/core/binding/caller.rdoc +0 -57
- data/demo/core/binding/defined.rdoc +0 -10
- data/demo/core/binding/eval.rdoc +0 -8
- data/demo/core/binding/local_variables.rdoc +0 -26
- data/demo/core/binding/opvars.rdoc +0 -16
- data/demo/core/binding/self.rdoc +0 -6
- data/demo/core/class/descendants.rdoc +0 -10
- data/demo/core/class/to_proc.rdoc +0 -8
- data/demo/core/comparable/cap.rdoc +0 -20
- data/demo/core/comparable/clip.rdoc +0 -37
- data/demo/core/comparable/cmp.rdoc +0 -18
- data/demo/core/comparable/op_get.rdoc +0 -29
- data/demo/core/dir/ascend.rdoc +0 -24
- data/demo/core/dir/descend.rdoc +0 -14
- data/demo/core/dir/multiglob.rdoc +0 -41
- data/demo/core/dir/parent.rdoc +0 -6
- data/demo/core/dir/recurse.rdoc +0 -41
- data/demo/core/exception/detail.rdoc +0 -12
- data/demo/core/filetest/root.rdoc +0 -6
- data/demo/core/hash/recursively.rdoc +0 -21
- data/demo/core/indexable.rdoc +0 -95
- data/demo/core/integer/bitmask.rdoc +0 -46
- data/demo/core/integer/even.rdoc +0 -12
- data/demo/core/integer/odd.rdoc +0 -12
- data/demo/core/matchdata/match.rdoc +0 -7
- data/demo/core/matchdata/matchset.rdoc +0 -15
- data/demo/core/module/cattr.rdoc +0 -43
- data/demo/core/module/class_extend.rdoc +0 -64
- data/demo/core/module/method_space.rdoc +0 -55
- data/demo/core/string/bytes.rdoc +0 -8
- data/demo/core/string/camelcase.rdoc +0 -47
- data/demo/core/string/characters.rdoc +0 -11
- data/demo/core/string/cleave.rdoc +0 -49
- data/demo/core/string/divide.rdoc +0 -9
- data/demo/core/string/each_char.rdoc +0 -9
- data/demo/core/string/each_word.rdoc +0 -9
- data/demo/core/string/end_with.rdoc +0 -6
- data/demo/core/string/expand_tabs.rdoc +0 -69
- data/demo/core/string/fold.rdoc +0 -14
- data/demo/core/string/indent.rdoc +0 -65
- data/demo/core/string/interpolate.rdoc +0 -7
- data/demo/core/string/lchomp.rdoc +0 -14
- data/demo/core/string/line_wrap.rdoc +0 -7
- data/demo/core/string/lines.rdoc +0 -8
- data/demo/core/string/methodize.rdoc +0 -22
- data/demo/core/string/modulize.rdoc +0 -22
- data/demo/core/string/mscan.rdoc +0 -10
- data/demo/core/string/natcmp.rdoc +0 -10
- data/demo/core/string/nchar.rdoc +0 -9
- data/demo/core/string/op_sub.rdoc +0 -7
- data/demo/core/string/pathize.rdoc +0 -22
- data/demo/core/string/quote.rdoc +0 -20
- data/demo/core/string/range.rdoc +0 -19
- data/demo/core/string/rewrite.rdoc +0 -9
- data/demo/core/string/shatter.rdoc +0 -9
- data/demo/core/string/snakecase.rdoc +0 -10
- data/demo/core/string/splice.rdoc +0 -28
- data/demo/core/string/start_with.rdoc +0 -7
- data/demo/core/string/subtract.rdoc +0 -8
- data/demo/core/string/tab.rdoc +0 -16
- data/demo/core/string/tabto.rdoc +0 -29
- data/demo/core/string/titlecase.rdoc +0 -8
- data/demo/core/string/to_re.rdoc +0 -22
- data/demo/core/string/unfold.rdoc +0 -9
- data/demo/core/string/unindent.rdoc +0 -65
- data/demo/core/string/unquote.rdoc +0 -6
- data/demo/core/string/variablize.rdoc +0 -7
- data/demo/core/string/word_wrap.rdoc +0 -54
- data/demo/core/string/words.rdoc +0 -13
- data/demo/core/string/xor.rdoc +0 -8
- data/lib/core/facets/binding/local_variables.rb +0 -16
- data/lib/core/facets/string/tab.rb +0 -2
- data/lib/core/facets/string/tabto.rb +0 -2
- data/test/core/array/test_after.rb +0 -27
- data/test/core/array/test_combination.rb +0 -25
- data/test/core/array/test_index.rb +0 -20
- data/test/core/array/test_permutation.rb +0 -20
- data/test/core/array/test_product.rb +0 -64
- data/test/core/array/test_rotate.rb +0 -38
- data/test/core/array/test_select.rb +0 -16
- data/test/core/binding/test_eval.rb +0 -15
- data/test/core/binding/test_local_variables.rb +0 -36
- data/test/core/enumerable/test_cluster_by.rb +0 -30
- data/test/core/enumerable/test_count.rb +0 -32
- data/test/core/enumerable/test_each_with_object.rb +0 -18
- data/test/core/enumerable/test_group_by.rb +0 -36
- data/test/core/enumerable/test_none.rb +0 -29
- data/test/core/enumerable/test_one.rb +0 -34
- data/test/core/enumerable/test_take.rb +0 -15
- data/test/core/hash/test_select.rb +0 -44
- data/test/core/hash/test_url_params.rb +0 -26
- data/test/core/integer/test_even.rb +0 -24
- data/test/core/integer/test_odd.rb +0 -24
- data/test/core/kernel/test_require_relative.rb +0 -12
- data/test/core/nilclass/test_to_f.rb +0 -13
- data/test/core/proc/test_curry.rb +0 -38
- data/test/core/string/test_bytes.rb +0 -13
- data/test/core/string/test_each_char.rb +0 -17
- data/test/core/string/test_end_with.rb +0 -24
- data/test/core/string/test_lines.rb +0 -15
- data/test/core/string/test_start_with.rb +0 -24
- data/test/core/string/test_tab.rb +0 -16
- data/test/core/symbol/test_to_proc.rb +0 -35
- data/test/core/to_hash_tc.rb +0 -210
- data/test/core/unboundmethod/test_name.rb +0 -19
@@ -1,47 +1,47 @@
|
|
1
|
-
|
1
|
+
## String#trim
|
2
2
|
|
3
|
-
require 'facets/string/
|
3
|
+
require 'facets/string/trim'
|
4
4
|
|
5
5
|
s = %q{
|
6
6
|
|ABC
|
7
7
|
|123
|
8
8
|
|TEST
|
9
|
-
}.
|
9
|
+
}.trim
|
10
10
|
s.assert == "ABC\n123\nTEST"
|
11
11
|
|
12
12
|
s = %q{
|
13
13
|
|ABC
|
14
14
|
|123
|
15
15
|
|TEST
|
16
|
-
}.
|
16
|
+
}.trim
|
17
17
|
s.assert == "ABC\n123\nTEST"
|
18
18
|
|
19
19
|
s = %q{|ABC
|
20
20
|
|123
|
21
21
|
|TEST
|
22
|
-
}.
|
22
|
+
}.trim
|
23
23
|
s.assert == "ABC\n123\nTEST"
|
24
24
|
|
25
25
|
s = %q{
|
26
26
|
|ABC
|
27
27
|
|123
|
28
|
-
|TEST}.
|
28
|
+
|TEST}.trim
|
29
29
|
s.assert == "ABC\n123\nTEST"
|
30
30
|
|
31
31
|
s = %q{|ABC
|
32
32
|
|123
|
33
|
-
|TEST}.
|
33
|
+
|TEST}.trim
|
34
34
|
s.assert == "ABC\n123\nTEST"
|
35
35
|
|
36
36
|
s = %q{ |ABC
|
37
37
|
|123
|
38
|
-
|TEST}.
|
38
|
+
|TEST}.trim
|
39
39
|
s.assert == "ABC\n123\nTEST"
|
40
40
|
|
41
41
|
s = %q{ABC
|
42
42
|
|123
|
43
43
|
|TEST
|
44
|
-
}.
|
44
|
+
}.trim
|
45
45
|
s.assert == "ABC\n123\nTEST"
|
46
46
|
|
47
47
|
spacing
|
@@ -50,27 +50,27 @@ spacing
|
|
50
50
|
| ABC
|
51
51
|
| 123
|
52
52
|
| TEST
|
53
|
-
}.
|
53
|
+
}.trim
|
54
54
|
s.assert == " ABC\n 123\n TEST"
|
55
55
|
|
56
56
|
s = %q{
|
57
57
|
|ABC
|
58
58
|
|123
|
59
59
|
|TEST
|
60
|
-
}.
|
60
|
+
}.trim(1)
|
61
61
|
s.assert == " ABC\n 123\n TEST"
|
62
62
|
|
63
63
|
s = %q{
|
64
64
|
|ABC
|
65
65
|
|123
|
66
66
|
|TEST
|
67
|
-
}.
|
67
|
+
}.trim(2)
|
68
68
|
s.assert == " ABC\n 123\n TEST"
|
69
69
|
|
70
70
|
s = %q{ ABC
|
71
71
|
- 123
|
72
72
|
- TEST
|
73
|
-
}.
|
73
|
+
}.trim
|
74
74
|
s.assert == " ABC\n 123\n TEST"
|
75
75
|
|
76
76
|
random placement
|
@@ -87,6 +87,6 @@ random placement
|
|
87
87
|
}
|
88
88
|
|
89
89
|
@volly.each{ |k,v|
|
90
|
-
k.
|
90
|
+
k.trim.assert == v
|
91
91
|
}
|
92
92
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
## String#unbracket
|
2
|
+
|
3
|
+
require 'facets/string/unbracket'
|
4
|
+
|
5
|
+
Remove matched paits of brackets from a string
|
6
|
+
|
7
|
+
s = "{unwrap me}"
|
8
|
+
z = s.unbracket('{')
|
9
|
+
z.assert == "unwrap me"
|
10
|
+
|
11
|
+
s = "--unwrap me!"
|
12
|
+
z = s.unbracket('--','!')
|
13
|
+
z.assert == "unwrap me"
|
14
|
+
|
15
|
+
## String#unbracket!
|
16
|
+
|
17
|
+
s = "{unwrap me}"
|
18
|
+
s.unbracket!('{')
|
19
|
+
s.assert == "unwrap me"
|
20
|
+
|
21
|
+
s = "--unwrap me!"
|
22
|
+
s.unbracket!('--','!')
|
23
|
+
s.assert == "unwrap me"
|
24
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
## String#underscore
|
2
|
+
|
3
|
+
require 'facets/string/underscore'
|
4
|
+
|
5
|
+
Underscore a string such that camelcase, dashes and spaces are
|
6
|
+
replaced by underscores. This is the reverse of {#camelcase},
|
7
|
+
albeit not an exact inverse.
|
8
|
+
|
9
|
+
Note, this method no longer converts `::` to `/`, in that case
|
10
|
+
use the {#pathize} method instead.
|
11
|
+
|
12
|
+
'my_name'.underscore.assert == 'my_name'
|
13
|
+
|
14
|
+
'MyName'.underscore.assert == 'my_name'
|
15
|
+
|
16
|
+
'URI'.underscore.assert == 'uri'
|
17
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
## String#unindent
|
2
|
+
|
3
|
+
require 'facets/string/unindent'
|
4
|
+
|
5
|
+
We will use these two strings as a common basis for demonstration.
|
6
|
+
|
7
|
+
ex1 = <<-EOF.gsub(/^\s*\|/,'')
|
8
|
+
| I must go down to the seas again
|
9
|
+
| The lonely sea and the sky
|
10
|
+
| And all I want is a tall ship
|
11
|
+
| And a star to steer her by
|
12
|
+
EOF
|
13
|
+
|
14
|
+
ex2 = <<-EOF.gsub(/^\s*\|/,'')
|
15
|
+
| "Eek!"
|
16
|
+
| She cried
|
17
|
+
| As the mouse quietly scurried
|
18
|
+
|by.
|
19
|
+
EOF
|
20
|
+
|
21
|
+
simple examples
|
22
|
+
|
23
|
+
" xyz".unindent(-1).assert == " xyz"
|
24
|
+
" xyz".unindent(0).assert == " xyz"
|
25
|
+
" xyz".unindent(1).assert == " xyz"
|
26
|
+
" xyz".unindent(2).assert == " xyz"
|
27
|
+
" xyz".unindent(3).assert == "xyz"
|
28
|
+
" xyz".unindent(4).assert == "xyz"
|
29
|
+
|
30
|
+
large example unindented one space
|
31
|
+
|
32
|
+
expected = <<-EOF.gsub(/^\s*\|/,'')
|
33
|
+
| I must go down to the seas again
|
34
|
+
| The lonely sea and the sky
|
35
|
+
| And all I want is a tall ship
|
36
|
+
| And a star to steer her by
|
37
|
+
EOF
|
38
|
+
|
39
|
+
actual = ex1.unindent(1)
|
40
|
+
actual.assert == expected
|
41
|
+
|
42
|
+
large example unindented four spaces
|
43
|
+
|
44
|
+
expected = <<-EOF.gsub(/^\s*\|/,'')
|
45
|
+
|I must go down to the seas again
|
46
|
+
| The lonely sea and the sky
|
47
|
+
|And all I want is a tall ship
|
48
|
+
| And a star to steer her by
|
49
|
+
EOF
|
50
|
+
|
51
|
+
actual = ex1.unindent(4)
|
52
|
+
actual.assert == expected
|
53
|
+
|
54
|
+
unindent larger than current indention
|
55
|
+
|
56
|
+
expected = <<-EOF.gsub(/^\s*\|/,'')
|
57
|
+
|"Eek!"
|
58
|
+
|She cried
|
59
|
+
|As the mouse quietly scurried
|
60
|
+
|by.
|
61
|
+
EOF
|
62
|
+
|
63
|
+
actual = ex2.unindent(100)
|
64
|
+
actual.assert == expected
|
65
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
## String#word_wrap
|
2
|
+
|
3
|
+
require 'facets/string/word_wrap'
|
4
|
+
|
5
|
+
e = "abcde\n12345\nxyzwu\n"
|
6
|
+
r = "abcde 12345 xyzwu".word_wrap(5)
|
7
|
+
r.assert == e
|
8
|
+
|
9
|
+
e = "abcd\n1234\nxyzw\n"
|
10
|
+
r = "abcd 1234 xyzw".word_wrap(4)
|
11
|
+
r.assert == e
|
12
|
+
|
13
|
+
e = "abc\n123\n"
|
14
|
+
r = "abc 123".word_wrap(4)
|
15
|
+
r.assert == e
|
16
|
+
|
17
|
+
e = "abc \n123\n"
|
18
|
+
r = "abc 123".word_wrap(4)
|
19
|
+
r.assert == e
|
20
|
+
|
21
|
+
e = "abc \n123\n"
|
22
|
+
r = "abc 123".word_wrap(4)
|
23
|
+
r.assert == e
|
24
|
+
|
25
|
+
## String#word_wrap!
|
26
|
+
|
27
|
+
w = "abcde 12345 xyzwu"
|
28
|
+
w.word_wrap!(5)
|
29
|
+
w.assert == "abcde\n12345\nxyzwu\n"
|
30
|
+
|
31
|
+
w = "abcd 1234 xyzw"
|
32
|
+
w.word_wrap!(4)
|
33
|
+
w.assert == "abcd\n1234\nxyzw\n"
|
34
|
+
|
35
|
+
w = "abc 123"
|
36
|
+
w.word_wrap!(4)
|
37
|
+
w.assert == "abc\n123\n"
|
38
|
+
|
39
|
+
w = "abc 123"
|
40
|
+
w.word_wrap!(4)
|
41
|
+
w.assert == "abc \n123\n"
|
42
|
+
|
43
|
+
w = "abc 123"
|
44
|
+
w.word_wrap!(4)
|
45
|
+
w.assert == "abc \n123\n"
|
46
|
+
|
47
|
+
# Unit :word_wrap do
|
48
|
+
# assert_equal "abcde-\n12345-\nxyzwu\n", "abcde12345xyzwu".word_wrap(6,2)
|
49
|
+
# assert_equal "abcd-\n1234-\nxyzw\n", "abcd1234xyzw".word_wrap(5,2)
|
50
|
+
# assert_equal "abc \n123\n", "abc 123".word_wrap(4,2)
|
51
|
+
# assert_equal "abc \n123\n", "abc 123".word_wrap(4,2)
|
52
|
+
# assert_equal "abc \n123\n", "abc 123".word_wrap(4,2)
|
53
|
+
# end
|
54
|
+
|
data/lib/core/facets.yml
CHANGED
@@ -12,24 +12,28 @@ organizations:
|
|
12
12
|
requirements:
|
13
13
|
- groups:
|
14
14
|
- test
|
15
|
-
version:
|
15
|
+
version: ">= 0"
|
16
16
|
name: lemon
|
17
17
|
- groups:
|
18
18
|
- test
|
19
|
-
version:
|
19
|
+
version: ">= 0"
|
20
20
|
name: qed
|
21
21
|
- groups:
|
22
22
|
- test
|
23
|
-
version:
|
23
|
+
version: ">= 0"
|
24
24
|
name: rubytest-cli
|
25
25
|
- groups:
|
26
26
|
- test
|
27
|
-
version:
|
27
|
+
version: ">= 0"
|
28
28
|
name: rake
|
29
29
|
- groups:
|
30
30
|
- test
|
31
|
-
version:
|
31
|
+
version: ">= 0"
|
32
32
|
name: simplecov
|
33
|
+
- groups:
|
34
|
+
- guard
|
35
|
+
version: ">= 0"
|
36
|
+
name: guard
|
33
37
|
conflicts: []
|
34
38
|
alternatives: []
|
35
39
|
resources:
|
@@ -63,7 +67,7 @@ paths:
|
|
63
67
|
- lib/standard
|
64
68
|
name: facets
|
65
69
|
title: Ruby Facets
|
66
|
-
version: 3.
|
70
|
+
version: 3.1.0
|
67
71
|
summary: The orginal well curated collection of extension methods for Ruby.
|
68
72
|
slogan: ALL YOUR BASE ARE BELONG TO RUBY!
|
69
73
|
description: Facets is the premier collection of extension methods for the Ruby programming
|
@@ -73,4 +77,4 @@ description: Facets is the premier collection of extension methods for the Ruby
|
|
73
77
|
applications.
|
74
78
|
scm_uri: https://github.com/rubyworks/facets/tree/master
|
75
79
|
created: '2004-12-16'
|
76
|
-
date: '
|
80
|
+
date: '2016-05-09'
|
data/lib/core/facets/array.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
# Calculate the average of an array of numbers
|
4
|
+
#
|
5
|
+
# Examples
|
6
|
+
#
|
7
|
+
# [].average #=> nil
|
8
|
+
# [1, 2, 3].average #=> 2
|
9
|
+
# [3, 12, 57, 85, 15, 89, 33, 7, 22, 54].average #=> 37.7
|
10
|
+
# [1,[2,nil,[3]],nil,4].collapse #=> [1,2,3,4]
|
11
|
+
#
|
12
|
+
def average
|
13
|
+
return nil if empty?
|
14
|
+
self.reduce(:+)/length.to_f
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/array/delete_values'
|
@@ -5,10 +5,17 @@ class Array
|
|
5
5
|
# ['a1','b1','a2','b2'].divide(/^a/)
|
6
6
|
# #=> [['a1','b1'],['a2','b2']]
|
7
7
|
#
|
8
|
+
# ['a1','b1','a2','b2'].divide(/^b/)
|
9
|
+
# #=> [['a1',['b1','a2'],[]'b2']]
|
10
|
+
#
|
11
|
+
# ['a1','b1','a2','b2'].divide(/^c/)
|
12
|
+
# #=> [['a1','b1','a2','b2']]
|
13
|
+
#
|
8
14
|
# CREDIT: Trans
|
9
15
|
|
10
16
|
def divide(pattern)
|
11
17
|
memo = []
|
18
|
+
memo.push [] unless pattern === first
|
12
19
|
each do |obj|
|
13
20
|
memo.push [] if pattern === obj
|
14
21
|
memo.last << obj
|