mack-facets 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gems.rb +25 -0
- data/lib/gems/english-0.3.1/VERSION +1 -0
- data/lib/gems/english-0.3.1/lib/english/array.rb +48 -0
- data/lib/gems/english-0.3.1/lib/english/censor.rb +76 -0
- data/lib/gems/english-0.3.1/lib/english/double_metaphone.rb +353 -0
- data/lib/gems/english-0.3.1/lib/english/dresner.rb +47 -0
- data/lib/gems/english-0.3.1/lib/english/inflect.rb +299 -0
- data/lib/gems/english-0.3.1/lib/english/jumble.rb +37 -0
- data/lib/gems/english-0.3.1/lib/english/levenshtein.rb +78 -0
- data/lib/gems/english-0.3.1/lib/english/metaphone.rb +110 -0
- data/lib/gems/english-0.3.1/lib/english/numerals.rb +71 -0
- data/lib/gems/english-0.3.1/lib/english/patterns.rb +49 -0
- data/lib/gems/english-0.3.1/lib/english/porter_stemming.rb +188 -0
- data/lib/gems/english-0.3.1/lib/english/roman.rb +174 -0
- data/lib/gems/english-0.3.1/lib/english/similarity.rb +103 -0
- data/lib/gems/english-0.3.1/lib/english/soundex.rb +70 -0
- data/lib/gems/english-0.3.1/lib/english/string.rb +210 -0
- data/lib/gems/english-0.3.1/lib/english/style.rb +294 -0
- data/lib/gems/english-0.3.1/lib/english/style_orm.rb +143 -0
- data/lib/gems/english-0.3.1/lib/english/textfilter.rb +91 -0
- data/lib/gems/extlib-0.9.8/lib/extlib.rb +56 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/assertions.rb +8 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/blank.rb +59 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/boolean.rb +11 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/class.rb +175 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/datetime.rb +9 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/dictionary.rb +433 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/hash.rb +419 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/hook.rb +366 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/inflection.rb +435 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/lazy_array.rb +106 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/logger.rb +202 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/mash.rb +148 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/module.rb +41 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/nil.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/numeric.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/object.rb +175 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/object_space.rb +13 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/pathname.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/pooling.rb +239 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/rubygems.rb +38 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb +39 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/string.rb +132 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/struct.rb +8 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/symbol.rb +17 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/tasks/release.rb +15 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/time.rb +19 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/version.rb +3 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/virtual_file.rb +10 -0
- data/lib/gems/facets-2.4.5/VERSION +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets-live.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets-load.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets.rb +11 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/combination.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/conjoin.rb +58 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/delete.rb +61 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/index.rb +48 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/indexable.rb +73 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/merge.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/not_empty.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/only.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/pad.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/permutation.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/product.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/recursively.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/rotate.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/select.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/splice.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/stackable.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/traverse.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/caller.rb +54 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/defined.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/eval.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/local_variables.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/self.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/bitmask.rb +104 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/blank.rb +60 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/boolean.rb +156 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/callstack.rb +52 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/cattr.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr.rb +115 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_accessor.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_reader.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_writer.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/descendents.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/methodize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/pathize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/prepend.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/subclasses.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/to_proc.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/bound.rb +65 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/cmp.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/comparable.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/ascend.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/descend.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/multiglob.rb +92 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/parent.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/recurse.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/accumulate.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/cluster_by.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/collect.rb +54 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/commonality.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/count.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/divide.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/duplicates.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/each_by.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/entropy.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/frequency.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/group_by.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/inject.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/map_send.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/mash.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/mode.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/modulate.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/none.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/occur.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/one.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/probability.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/split.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/sum.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/uniq_by.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception/detail.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception/suppress.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/append.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/create.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/null.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/read.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/rewrite.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/rootname.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/split_root.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/write.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/writelines.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/filetest.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/filetest/root.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/float.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/float/round.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/functor.rb +77 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/alias.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/argumentize.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/at.rb +8 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/autonew.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/collate.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/delete.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/diff.rb +11 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/except.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/insert.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/inverse.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/join.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/keys.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/mash.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/merge.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op.rb +7 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_add.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_and.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_mul.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_or.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_push.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_sub.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/recursive_merge.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/recursively.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/rekey.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/select.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/slice.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/swap.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_h.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_proc.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_struct.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/traverse.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/update.rb +81 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/weave.rb +81 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/zipnew.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/indexable.rb +251 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/even.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/factorial.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/multiple.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/odd.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/of.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/ordinal.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__callee__.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__class__.rb +9 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__dir__.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__get__.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__method__.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__set__.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/as.rb +100 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/ask.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/attr_singleton.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/complete.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/constant.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/d.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/deep_copy.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/demo.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/ergo.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/here.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/in.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_assign.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_class.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_exec.rb +40 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_send.rb +7 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_variables.rb +99 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/maybe.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/not_nil.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_class.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_hexid.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_send.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/p.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/populate.rb +73 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/qua_class.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/require_all.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/require_local.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/resc.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/respond.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/returning.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/silence.rb +75 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/singleton_class.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/tap.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/try.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/val.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/with.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/lazy.rb +238 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata/match.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata/matchset.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/metaid.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/abstract.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_accessor.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_method_chain.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_module_function.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/ancestor.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/basename.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/can.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/class.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/conflict.rb +63 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/include_function_module.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/instance_methods.rb +40 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/integrate.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/is.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/methodize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/modspace.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/module_load.rb +56 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/nesting.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/op.rb +95 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/pathize.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/prepend.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/redefine_method.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/redirect_method.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/rename_method.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/revise.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/spacename.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/wrap_method.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass/ergo.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass/to_f.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/approx.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/distance.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/round.rb +72 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/bind.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/compose.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/curry.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/to_method.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/update.rb +9 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/combine.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/overlap.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/to_r.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/umbrella.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/within.rb +66 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp/arity.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp/to_re.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/stackable.rb +86 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/align.rb +106 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/bracket.rb +105 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/bytes.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/camelcase.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/capitalized.rb +46 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/chars.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/chomp.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/cleave.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/divide.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/each_char.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/each_word.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/end_with.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/fold.rb +39 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/interpolate.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/line_wrap.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/lines.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/methodize.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/modulize.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/mscan.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/natcmp.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/nchar.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/op_sub.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/pathize.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/range.rb +77 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/rewrite.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/shatter.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/snakecase.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/splice.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/start_with.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/subtract.rb +4 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/tab.rb +103 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/titlecase.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/to_re.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/variablize.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/word_wrap.rb +34 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/words.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/xor.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/chomp.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/generate.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/not.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/plain.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/query.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/re_s.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/setter.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/succ.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/to_proc.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/variablize.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/advance.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/ago.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/change.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/elapse.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/hence.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/round.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/set.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/stamp.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/to_time.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/trunc.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/to_hash.rb +87 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/arguments.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/name.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/basicobject.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/cgi.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/continuation.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/date.rb +396 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/head.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/safe_ln.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/slice.rb +141 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/tail.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/wc.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/whereis.rb +64 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/which.rb +101 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/getoptlong.rb +71 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/logger.rb +291 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/ostruct.rb +238 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/pathname.rb +172 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/rbconfig.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/set.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/shellwords.rb +89 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/uri.rb +249 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/yaml.rb +75 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/zlib.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/1stclassmethod.rb +140 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/advisable.rb +162 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/annotations.rb +302 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ansicode.rb +315 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/arguments.rb +365 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/argvector.rb +353 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/association.rb +194 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/attr.rb +208 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/autoarray.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/autoreload.rb +150 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/basex.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bbcode.rb +397 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bicrypt.rb +265 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/binding/opvars.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/binreadable.rb +221 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/blankslate.rb +66 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/buildable.rb +344 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bytes.rb +175 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cachedecorator.rb +117 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/capsule.rb +258 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/chain.rb +58 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/class_extension.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/classmethods.rb +199 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cloneable.rb +76 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/command.rb +439 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/consoleutils.rb +113 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/coroutine.rb +159 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/crypt.rb +166 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cssfilter.rb +254 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/daemonize.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dependency.rb +151 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dictionary.rb +478 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dictionarymatcher.rb +136 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/downloader.rb +281 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/duplicable.rb +43 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/duration.rb +540 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/elementor.rb +133 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/elementwise.rb +61 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/enumerablepass.rb +217 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/equatable.rb +120 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/eventhook.rb +132 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/expirable.rb +82 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/fileable.rb +162 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/filelist.rb +497 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb +202 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/hash/stringify_keys.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/hash/symbolize_keys.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/heap.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/htmlfilter.rb +595 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/infinity.rb +193 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/inheritor.rb +130 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ini.rb +264 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantiable.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantise.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantize.rb +95 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/interval.rb +282 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ioredirect.rb +130 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/iteration.rb +65 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/kernel/meta.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/linkedlist.rb +222 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/lrucache.rb +157 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/main.rb +70 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/memoize.rb +116 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/methodspace.rb +141 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/minitar.rb +1063 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/multipliers.rb +109 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/multiton.rb +386 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nackclass.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/net/smtp_tls.rb +131 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nilstatus.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nullclass.rb +74 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opencascade.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opencollection.rb +43 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/openhash.rb +39 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/openobject.rb +267 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opesc.rb +60 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/orderedhash.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/overload.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/paramix.rb +202 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/partial.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pathlist.rb +112 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/platform.rb +192 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pool.rb +91 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pqueue.rb +449 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/progressbar.rb +253 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/prototype.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/random.rb +451 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/rbsystem.rb +222 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/recorder.rb +109 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/reference.rb +99 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/reflection.rb +145 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/registerable.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/rwdelegator.rb +74 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/semaphore.rb +92 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/settings.rb +248 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/snapshot.rb +209 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/string/mask.rb +278 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/string/words.rb +173 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/succ.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/syncarray.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/synchash.rb +157 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tagiter.rb +366 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/thread.rb +51 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/timer.rb +274 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/times.rb +431 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tracepoint.rb +209 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tuple.rb +325 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/typecast.rb +261 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/uninheritable.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/uploadutils.rb +464 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/version.rb +136 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/xmlhash.rb +112 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/xoxo.rb +259 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ziputils.rb +349 -0
- data/lib/mack-facets.rb +4 -2
- data/lib/mack-facets/english_extensions/inflect.rb +50 -50
- data/lib/mack-facets/extensions/string.rb +10 -1
- data/lib/mack-facets/utils/inflections.rb +50 -47
- data/lib/mack-facets/utils/inflector.rb +19 -19
- metadata +547 -36
@@ -0,0 +1,253 @@
|
|
1
|
+
# = Progressbar
|
2
|
+
#
|
3
|
+
# ProgressBar is a text-based progressbar library.
|
4
|
+
#
|
5
|
+
# == Usage
|
6
|
+
#
|
7
|
+
# pbar = ProgressBar.new( "Demo", 100 )
|
8
|
+
# 100.times { pbar.inc }
|
9
|
+
# pbar.finish
|
10
|
+
#
|
11
|
+
# == Copying
|
12
|
+
#
|
13
|
+
# Copyright (C) 2001 Satoru Takabayashi
|
14
|
+
#
|
15
|
+
# Ruby License
|
16
|
+
#
|
17
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
18
|
+
# software under the same terms as Ruby.
|
19
|
+
#
|
20
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
21
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
22
|
+
# FOR A PARTICULAR PURPOSE.
|
23
|
+
#
|
24
|
+
# == Author
|
25
|
+
#
|
26
|
+
# * Satoru Takabayashi
|
27
|
+
|
28
|
+
# = ProgressBar
|
29
|
+
#
|
30
|
+
# ProgressBar is a text-based progressbar library.
|
31
|
+
#
|
32
|
+
# pbar = ProgressBar.new( "Demo", 100 )
|
33
|
+
# 100.times { pbar.inc }
|
34
|
+
# pbar.finish
|
35
|
+
#
|
36
|
+
class ProgressBar
|
37
|
+
|
38
|
+
def initialize(title, total, out = STDERR)
|
39
|
+
@title = title
|
40
|
+
@total = total
|
41
|
+
@out = out
|
42
|
+
@bar_length = 80
|
43
|
+
@bar_mark = "o"
|
44
|
+
@total_overflow = true
|
45
|
+
@current = 0
|
46
|
+
@previous = 0
|
47
|
+
@is_finished = false
|
48
|
+
@start_time = Time.now
|
49
|
+
@format = "%-14s %3d%% %s %s"
|
50
|
+
@format_arguments = [:title, :percentage, :bar, :stat]
|
51
|
+
show_progress
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def convert_bytes (bytes)
|
56
|
+
if bytes < 1024
|
57
|
+
sprintf("%6dB", bytes)
|
58
|
+
elsif bytes < 1024 * 1000 # 1000kb
|
59
|
+
sprintf("%5.1fKB", bytes.to_f / 1024)
|
60
|
+
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
61
|
+
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
62
|
+
else
|
63
|
+
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def transfer_rate
|
68
|
+
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
69
|
+
sprintf("%s/s", convert_bytes(bytes_per_second))
|
70
|
+
end
|
71
|
+
|
72
|
+
def bytes
|
73
|
+
convert_bytes(@current)
|
74
|
+
end
|
75
|
+
|
76
|
+
def format_time(t)
|
77
|
+
t = t.to_i
|
78
|
+
sec = t % 60
|
79
|
+
min = (t / 60) % 60
|
80
|
+
hour = t / 3600
|
81
|
+
sprintf("%02d:%02d:%02d", hour, min, sec);
|
82
|
+
end
|
83
|
+
|
84
|
+
# ETA stands for Estimated Time of Arrival.
|
85
|
+
def eta
|
86
|
+
if @current == 0
|
87
|
+
"ETA: --:--:--"
|
88
|
+
else
|
89
|
+
elapsed = Time.now - @start_time
|
90
|
+
eta = elapsed * @total / @current - elapsed;
|
91
|
+
sprintf("ETA: %s", format_time(eta))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def elapsed
|
96
|
+
elapsed = Time.now - @start_time
|
97
|
+
sprintf("Time: %s", format_time(elapsed))
|
98
|
+
end
|
99
|
+
|
100
|
+
def stat
|
101
|
+
if @is_finished then elapsed else eta end
|
102
|
+
end
|
103
|
+
|
104
|
+
def stat_for_file_transfer
|
105
|
+
if @is_finished then
|
106
|
+
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
107
|
+
else
|
108
|
+
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def eol
|
113
|
+
if @is_finished then "\n" else "\r" end
|
114
|
+
end
|
115
|
+
|
116
|
+
def bar
|
117
|
+
len = percentage * @bar_length / 100
|
118
|
+
sprintf("|%s%s|", @bar_mark * len, " " * (@bar_length - len))
|
119
|
+
end
|
120
|
+
|
121
|
+
def percentage
|
122
|
+
if @total.zero?
|
123
|
+
100
|
124
|
+
else
|
125
|
+
@current * 100 / @total
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def title
|
130
|
+
@title[0,13] + ":"
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_width
|
134
|
+
# FIXME: I don't know how portable it is.
|
135
|
+
default_width = 80
|
136
|
+
begin
|
137
|
+
tiocgwinsz = 0x5413
|
138
|
+
data = [0, 0, 0, 0].pack("SSSS")
|
139
|
+
if @out.ioctl(tiocgwinsz, data) >= 0 then
|
140
|
+
rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
141
|
+
if cols >= 0 then cols else default_width end
|
142
|
+
else
|
143
|
+
default_width
|
144
|
+
end
|
145
|
+
rescue Exception
|
146
|
+
default_width
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def show
|
151
|
+
arguments = @format_arguments.map{|method| send(method)}
|
152
|
+
line = sprintf(@format, *arguments)
|
153
|
+
|
154
|
+
width = get_width
|
155
|
+
if line.length == width - 1
|
156
|
+
@out.print(line + eol)
|
157
|
+
elsif line.length >= width
|
158
|
+
@bar_length = [@bar_length - (line.length - width + 1), 0].max
|
159
|
+
if @bar_length == 0 then @out.print(line + eol) else show end
|
160
|
+
else #line.length < width - 1
|
161
|
+
@bar_length += width - line.length + 1
|
162
|
+
show
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def show_progress
|
167
|
+
if @total.zero?
|
168
|
+
cur_percentage = 100
|
169
|
+
prev_percentage = 0
|
170
|
+
else
|
171
|
+
cur_percentage = (@current * 100 / @total).to_i
|
172
|
+
prev_percentage = (@previous * 100 / @total).to_i
|
173
|
+
end
|
174
|
+
|
175
|
+
if cur_percentage > prev_percentage || @is_finished
|
176
|
+
show
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
public
|
181
|
+
def file_transfer_mode
|
182
|
+
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
183
|
+
end
|
184
|
+
|
185
|
+
def title=(str)
|
186
|
+
@title = str
|
187
|
+
end
|
188
|
+
|
189
|
+
def bar_mark=(mark)
|
190
|
+
@bar_mark = String(mark)[0..0]
|
191
|
+
end
|
192
|
+
|
193
|
+
def total_overflow=(boolv)
|
194
|
+
@total_overflow = boolv ? true : false
|
195
|
+
end
|
196
|
+
|
197
|
+
def format=(format)
|
198
|
+
@format = format
|
199
|
+
end
|
200
|
+
|
201
|
+
def format_arguments=(arguments)
|
202
|
+
@format_arguments = arguments
|
203
|
+
end
|
204
|
+
|
205
|
+
def finish
|
206
|
+
@current = @total
|
207
|
+
@is_finished = true
|
208
|
+
show_progress
|
209
|
+
end
|
210
|
+
|
211
|
+
def flush
|
212
|
+
@out.flush
|
213
|
+
end
|
214
|
+
|
215
|
+
def halt
|
216
|
+
@is_finished = true
|
217
|
+
show_progress
|
218
|
+
end
|
219
|
+
|
220
|
+
def set(count)
|
221
|
+
if count < 0
|
222
|
+
raise "invalid count less than zero: #{count}"
|
223
|
+
elsif count > @total
|
224
|
+
if @total_overflow
|
225
|
+
@total = count + 1
|
226
|
+
else
|
227
|
+
raise "invalid count greater than total: #{count}"
|
228
|
+
end
|
229
|
+
end
|
230
|
+
@current = count
|
231
|
+
show_progress
|
232
|
+
@previous = @current
|
233
|
+
end
|
234
|
+
|
235
|
+
def inc(step = 1)
|
236
|
+
@current += step
|
237
|
+
@current = @total if @current > @total
|
238
|
+
show_progress
|
239
|
+
@previous = @current
|
240
|
+
end
|
241
|
+
|
242
|
+
def inspect
|
243
|
+
"(ProgressBar: #{@current}/#{@total})"
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
|
249
|
+
module Console #:nodoc:
|
250
|
+
# For backward compatibility
|
251
|
+
ProgressBar = ::ProgressBar
|
252
|
+
end
|
253
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# = Prototype
|
2
|
+
#
|
3
|
+
# Prototype-base Object-Oriented programming.
|
4
|
+
#
|
5
|
+
# == Copying
|
6
|
+
#
|
7
|
+
# Copyright (c) 2006, 2007 Thomas Sawyer
|
8
|
+
|
9
|
+
|
10
|
+
# = Prototype
|
11
|
+
#
|
12
|
+
class Prototype
|
13
|
+
|
14
|
+
# New prototype object.
|
15
|
+
|
16
|
+
def initialize(&block)
|
17
|
+
@traits = []
|
18
|
+
|
19
|
+
instance_eval(&block)
|
20
|
+
|
21
|
+
h = {}
|
22
|
+
iv = instance_variables
|
23
|
+
iv.each { |k| h[k[1..-1].to_sym] = instance_eval{ instance_variable_get(k) } }
|
24
|
+
meta.class_eval do
|
25
|
+
h.each do |k,v|
|
26
|
+
case v
|
27
|
+
when Proc
|
28
|
+
#define_method(k){ |*args| v[*args] }
|
29
|
+
attr_reader k
|
30
|
+
else
|
31
|
+
attr_accessor k
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def fn(&blk)
|
38
|
+
proc(&blk)
|
39
|
+
end
|
40
|
+
|
41
|
+
def new(o=nil)
|
42
|
+
return o.clone if o
|
43
|
+
return clone
|
44
|
+
end
|
45
|
+
|
46
|
+
def meta
|
47
|
+
(class << self; self; end)
|
48
|
+
end
|
49
|
+
|
50
|
+
def traits
|
51
|
+
@traits
|
52
|
+
end
|
53
|
+
|
54
|
+
def trait(obj)
|
55
|
+
traits << obj.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(s, *a, &b)
|
59
|
+
if trait = traits.find{ |t| t.method_defined?(s) }
|
60
|
+
trait.send(s,*a,&b)
|
61
|
+
else
|
62
|
+
super
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
module Kernel
|
70
|
+
|
71
|
+
def prototype(&block)
|
72
|
+
Prototype.new(&block)
|
73
|
+
end
|
74
|
+
|
75
|
+
#private
|
76
|
+
|
77
|
+
# Synonymous with #clone, this is an interesting
|
78
|
+
# method in that it promotes prototype-based Ruby.
|
79
|
+
# Now Classes aren't the only things that respond to #new.
|
80
|
+
#
|
81
|
+
# "ABC".new => "ABC"
|
82
|
+
#
|
83
|
+
def new(o=nil)
|
84
|
+
return o.clone if o
|
85
|
+
return clone
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,451 @@
|
|
1
|
+
# = Random
|
2
|
+
#
|
3
|
+
# Randomization core extension methods.
|
4
|
+
#
|
5
|
+
# This library extends Object, Array, String and Hash with randomization
|
6
|
+
# methods. Most of the methods are of one of two kinds. Either they "pick"
|
7
|
+
# a random element from the reciever or they randomly "shuffle" the reciever.
|
8
|
+
#
|
9
|
+
# The most common example is Array#shuffle, which simply randmomizes the
|
10
|
+
# order of an array's elements.
|
11
|
+
#
|
12
|
+
# [1,2,3].shuffle #=> [2,3,1]
|
13
|
+
#
|
14
|
+
# The other methods do similar things for their respective classes.
|
15
|
+
#
|
16
|
+
# == Authors
|
17
|
+
#
|
18
|
+
# * Ilmari Heikkinen <mailto:kig@misfiring.net>
|
19
|
+
# * Christian Neukirchen <mailto:chneukirchen@gmail.com>
|
20
|
+
# * Thomas Sawyer
|
21
|
+
#
|
22
|
+
# == Copying
|
23
|
+
#
|
24
|
+
# Copyright (c) 2005 Ilmari Heikkinen, Christian Neukirchen, Thomas Sawyer
|
25
|
+
#
|
26
|
+
# Ruby License
|
27
|
+
#
|
28
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
29
|
+
# software under the same terms as Ruby.
|
30
|
+
#
|
31
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
32
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
33
|
+
# FOR A PARTICULAR PURPOSE.
|
34
|
+
|
35
|
+
require 'facets/hash/zipnew'
|
36
|
+
require 'facets/string/shatter'
|
37
|
+
|
38
|
+
# = Random
|
39
|
+
#
|
40
|
+
# Randomization core extension methods.
|
41
|
+
#
|
42
|
+
# This library extends Array, String and Hash with randomization methods.
|
43
|
+
# Most of the methods are of one of two kinds. Either they "pick" a random
|
44
|
+
# element from the reciever or they randomly "shuffle" the reciever.
|
45
|
+
#
|
46
|
+
# The most common example is Array#shuffle, which simply randmomizes the
|
47
|
+
# order of an array's elements.
|
48
|
+
#
|
49
|
+
# [1,2,3].shuffle #=> [2,3,1]
|
50
|
+
#
|
51
|
+
# The other methods do similar things for their respective classes.
|
52
|
+
#
|
53
|
+
module Random
|
54
|
+
|
55
|
+
class << self
|
56
|
+
# alias to Kernel method #rand.
|
57
|
+
alias_method :number, :rand
|
58
|
+
public :number
|
59
|
+
end
|
60
|
+
|
61
|
+
#def self.number(*args)
|
62
|
+
# ::Kernel.rand(*args)
|
63
|
+
#end
|
64
|
+
|
65
|
+
#
|
66
|
+
def self.append_features(mod)
|
67
|
+
if mod == ::Object
|
68
|
+
mod.send(:include, Random::Object)
|
69
|
+
elsif mod == ::Array
|
70
|
+
mod.send(:include, Random::Array)
|
71
|
+
elsif mod == ::Hash
|
72
|
+
mod.send(:include, Random::Hash)
|
73
|
+
elsif mod == ::String
|
74
|
+
mod.send(:include, Random::String)
|
75
|
+
else
|
76
|
+
raise TypeError
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
module Object
|
81
|
+
|
82
|
+
# Random generator that returns true or false.
|
83
|
+
# Can also take a block that has a 50/50 chance to being executed.
|
84
|
+
#
|
85
|
+
# maybe #=> true
|
86
|
+
# maybe #=> false
|
87
|
+
#
|
88
|
+
def maybe(chance = 0.5, &block)
|
89
|
+
if block then
|
90
|
+
yield if rand < chance
|
91
|
+
else
|
92
|
+
rand < chance
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
|
100
|
+
module Array
|
101
|
+
|
102
|
+
# Return a random element of the array.
|
103
|
+
#
|
104
|
+
# [1, 2, 3, 4].at_rand #=> 2
|
105
|
+
# [1, 2, 3, 4].at_rand #=> 4
|
106
|
+
#
|
107
|
+
def at_rand
|
108
|
+
at(Random.number(size))
|
109
|
+
end
|
110
|
+
|
111
|
+
# Same as #at_rand, but acts in place removing a
|
112
|
+
# random element from the array.
|
113
|
+
#
|
114
|
+
# a = [1,2,3,4]
|
115
|
+
# a.at_rand! #=> 2
|
116
|
+
# a #=> [1,3,4]
|
117
|
+
#
|
118
|
+
def at_rand!
|
119
|
+
return delete_at( Random.number( size ) )
|
120
|
+
end
|
121
|
+
|
122
|
+
# Similar to #at_rand, but will return an array of randomly
|
123
|
+
# picked exclusive elements if given a number.
|
124
|
+
def pick(n=nil)
|
125
|
+
if n
|
126
|
+
a = self.dup
|
127
|
+
a.pick!(n)
|
128
|
+
else
|
129
|
+
at(Random.number(size))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Similar to #at_rand!, but given a number will return
|
134
|
+
# an array of exclusive elements.
|
135
|
+
def pick!(n=nil)
|
136
|
+
if n
|
137
|
+
if n > self.size
|
138
|
+
r = self.dup
|
139
|
+
self.replace([])
|
140
|
+
r
|
141
|
+
else
|
142
|
+
r = []
|
143
|
+
n.times { r << delete_at(Random.number(size)) }
|
144
|
+
r
|
145
|
+
end
|
146
|
+
else
|
147
|
+
delete_at(Random.number(size))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Random index.
|
152
|
+
#
|
153
|
+
def rand_index
|
154
|
+
Random.number(size)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Returns a random subset of an Array. If a _number_
|
158
|
+
# of elements is specified then returns that number of
|
159
|
+
# elements, otherwise returns a random number of elements
|
160
|
+
# upto the size of the Array.
|
161
|
+
#
|
162
|
+
# By defualt the returned values are exclusive of
|
163
|
+
# each other, but if _exclusive_ is set to <tt>false</tt>,
|
164
|
+
# the same values can be choosen more than once.
|
165
|
+
#
|
166
|
+
# When _exclusive_ is <tt>true</tt> (the default) and the
|
167
|
+
# _number_ given is greater than the size of the array,
|
168
|
+
# then all values are returned.
|
169
|
+
#
|
170
|
+
# [1, 2, 3, 4].rand_subset(1) #=> [2]
|
171
|
+
# [1, 2, 3, 4].rand_subset(4) #=> [2, 1, 3, 4]
|
172
|
+
# [1, 2, 3, 4].rand_subset #=> [1, 3, 4]
|
173
|
+
# [1, 2, 3, 4].rand_subset #=> [2, 3]
|
174
|
+
#
|
175
|
+
def rand_subset( number=nil, exclusive=true )
|
176
|
+
number = Random.number(size) unless number
|
177
|
+
number = number.to_int
|
178
|
+
#return self.dup if (number >= size and exlusive)
|
179
|
+
return sort_by{rand}.slice(0,number) if exclusive
|
180
|
+
ri =[]; number.times { |n| ri << Random.number(size) }
|
181
|
+
return values_at(*ri)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Randomize the order of an array.
|
185
|
+
#
|
186
|
+
# [1,2,3,4].shuffle #=> [2,4,1,3]
|
187
|
+
#
|
188
|
+
def shuffle
|
189
|
+
dup.shuffle!
|
190
|
+
#sort_by{Random.number}
|
191
|
+
end
|
192
|
+
|
193
|
+
# As with #shuffle but modifies the array in place.
|
194
|
+
# The algorithm used here is known as a Fisher-Yates shuffle.
|
195
|
+
#
|
196
|
+
# a = [1,2,3,4]
|
197
|
+
# a.shuffle!
|
198
|
+
# a #=> [2,4,1,3]
|
199
|
+
#
|
200
|
+
# CREDIT Niel Spring
|
201
|
+
|
202
|
+
def shuffle!
|
203
|
+
s = size
|
204
|
+
each_index do |j|
|
205
|
+
i = Random.number(s-j)
|
206
|
+
#self[j], self[j+i] = self[j+i], self[j]
|
207
|
+
tmp = self[j]
|
208
|
+
self[j] = self[j+i]
|
209
|
+
self[j+i] = tmp
|
210
|
+
end
|
211
|
+
self
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
#
|
217
|
+
|
218
|
+
module Hash
|
219
|
+
|
220
|
+
# Returns a random key.
|
221
|
+
#
|
222
|
+
# {:one => 1, :two => 2, :three => 3}.pick_key #=> :three
|
223
|
+
#
|
224
|
+
def rand_key
|
225
|
+
keys.at(Random.number(keys.size))
|
226
|
+
end
|
227
|
+
|
228
|
+
# Delete a random key-value pair, returning the key.
|
229
|
+
#
|
230
|
+
# a = {:one => 1, :two => 2, :three => 3}
|
231
|
+
# a.pick_key! #=> :two
|
232
|
+
# a #=> {:one => 1, :three => 3}
|
233
|
+
#
|
234
|
+
def rand_key!
|
235
|
+
k,v = rand_pair
|
236
|
+
delete(k)
|
237
|
+
return k
|
238
|
+
end
|
239
|
+
|
240
|
+
alias_method( :pick_key, :rand_key! )
|
241
|
+
|
242
|
+
# Returns a random key-value pair.
|
243
|
+
#
|
244
|
+
# {:one => 1, :two => 2, :three => 3}.pick #=> [:one, 1]
|
245
|
+
#
|
246
|
+
def rand_pair
|
247
|
+
k = rand_key
|
248
|
+
return k, fetch(k)
|
249
|
+
end
|
250
|
+
|
251
|
+
# Deletes a random key-value pair and returns that pair.
|
252
|
+
#
|
253
|
+
# a = {:one => 1, :two => 2, :three => 3}
|
254
|
+
# a.rand_pair! #=> [:two, 2]
|
255
|
+
# a #=> {:one => 1, :three => 3}
|
256
|
+
#
|
257
|
+
def rand_pair!
|
258
|
+
k,v = rand_pair
|
259
|
+
delete( k )
|
260
|
+
return k,v
|
261
|
+
end
|
262
|
+
|
263
|
+
alias_method( :pick_pair, :rand_pair! )
|
264
|
+
|
265
|
+
# Returns a random hash value.
|
266
|
+
#
|
267
|
+
# {:one => 1, :two => 2, :three => 3}.rand_value #=> 2
|
268
|
+
# {:one => 1, :two => 2, :three => 3}.rand_value #=> 1
|
269
|
+
#
|
270
|
+
def rand_value
|
271
|
+
fetch(rand_key)
|
272
|
+
end
|
273
|
+
|
274
|
+
# Deletes a random key-value pair and returns the value.
|
275
|
+
#
|
276
|
+
# a = {:one => 1, :two => 2, :three => 3}
|
277
|
+
# a.at_rand! #=> 2
|
278
|
+
# a #=> {:one => 1, :three => 3}
|
279
|
+
#
|
280
|
+
def rand_value!
|
281
|
+
k,v = rand_pair
|
282
|
+
delete( k )
|
283
|
+
return v
|
284
|
+
end
|
285
|
+
|
286
|
+
alias_method( :pick, :rand_value! )
|
287
|
+
|
288
|
+
alias_method( :at_rand, :rand_value )
|
289
|
+
alias_method( :at_rand!, :rand_value! )
|
290
|
+
|
291
|
+
# Returns a copy of the hash with _values_ arranged
|
292
|
+
# in new random order.
|
293
|
+
#
|
294
|
+
# h = {:a=>1, :b=>2, :c=>3}
|
295
|
+
# h.shuffle_hash #=> {:b=>2, :c=>1, :a>3}
|
296
|
+
#
|
297
|
+
def shuffle
|
298
|
+
::Hash.zipnew( keys.sort_by{Random.number}, values.sort_by{Random.number} )
|
299
|
+
end
|
300
|
+
|
301
|
+
# Destructive shuffle_hash. Arrange the values in
|
302
|
+
# a new random order.
|
303
|
+
#
|
304
|
+
# h = {:a => 1, :b => 2, :c => 3}
|
305
|
+
# h.shuffle_hash!
|
306
|
+
# h #=> {:b=>2, :c=>1, :a=>3}
|
307
|
+
#
|
308
|
+
def shuffle!
|
309
|
+
self.replace(shuffle)
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
#
|
315
|
+
|
316
|
+
module String
|
317
|
+
|
318
|
+
def self.included(base)
|
319
|
+
base.extend(Self)
|
320
|
+
end
|
321
|
+
|
322
|
+
# Class-level methods.
|
323
|
+
|
324
|
+
module Self
|
325
|
+
|
326
|
+
# Returns a randomly generated string. One possible use is
|
327
|
+
# password initialization. Takes a max legnth of characters
|
328
|
+
# (default 8) and an optional valid char Regexp (default /\w\d/).
|
329
|
+
#
|
330
|
+
#--
|
331
|
+
# CREDIT George Moschovitis
|
332
|
+
#
|
333
|
+
# NOTE This is not very efficient. Better way?
|
334
|
+
#++
|
335
|
+
|
336
|
+
def random(max_length = 8, char_re = /[\w\d]/)
|
337
|
+
# gmosx: this is a nice example of input parameter checking.
|
338
|
+
# this is NOT a real time called method so we can add this
|
339
|
+
# check. Congrats to the author.
|
340
|
+
raise ArgumentError.new('char_re must be a regular expression!') unless char_re.is_a?(Regexp)
|
341
|
+
string = ""
|
342
|
+
while string.length < max_length
|
343
|
+
ch = Random.number(255).chr
|
344
|
+
string << ch if ch =~ char_re
|
345
|
+
end
|
346
|
+
return string
|
347
|
+
end
|
348
|
+
|
349
|
+
# Module method to generate a random letter.
|
350
|
+
#
|
351
|
+
# String::Random.rand_letter #=> "q"
|
352
|
+
# String::Random.rand_letter #=> "r"
|
353
|
+
# String::Random.rand_letter #=> "a"
|
354
|
+
#
|
355
|
+
def rand_letter
|
356
|
+
(Random.number(26) + (Random.number(2) == 0 ? 65 : 97) ).chr
|
357
|
+
end
|
358
|
+
|
359
|
+
end
|
360
|
+
|
361
|
+
# Return a random separation of the string.
|
362
|
+
# Default separation is by charaacter.
|
363
|
+
#
|
364
|
+
# "Ruby rules".at_rand(' ') #=> ["Ruby"]
|
365
|
+
#
|
366
|
+
def at_rand( separator=// )
|
367
|
+
#separator = self.class.patterns( separator )
|
368
|
+
self.split(separator,-1).at_rand
|
369
|
+
end
|
370
|
+
|
371
|
+
# Return a random separation while removing it
|
372
|
+
# from the string. Default separation is by character.
|
373
|
+
#
|
374
|
+
# s = "Ruby rules"
|
375
|
+
# s = at_rand!(' ') #=> "Ruby"
|
376
|
+
# s #=> "rules"
|
377
|
+
#
|
378
|
+
def at_rand!( separator=// )
|
379
|
+
#separator = self.class.patterns( separator )
|
380
|
+
a = self.shatter( separator )
|
381
|
+
w = []; a.each_with_index { |s,i| i % 2 == 0 ? w << s : w.last << s }
|
382
|
+
i = Random.number(w.size)
|
383
|
+
r = w.delete_at( i )
|
384
|
+
self.replace( w.join('') )
|
385
|
+
return r
|
386
|
+
end
|
387
|
+
|
388
|
+
# Return a random byte of _self_.
|
389
|
+
#
|
390
|
+
# "Ruby rules".rand_byte #=> 121
|
391
|
+
#
|
392
|
+
def rand_byte
|
393
|
+
self[Random.number(size)]
|
394
|
+
end
|
395
|
+
|
396
|
+
# Destructive rand_byte. Delete a random byte of _self_ and return it.
|
397
|
+
#
|
398
|
+
# s = "Ruby rules"
|
399
|
+
# s.rand_byte! #=> 121
|
400
|
+
# s #=> "Rub rules"
|
401
|
+
#
|
402
|
+
def rand_byte!
|
403
|
+
i = Random.number(size)
|
404
|
+
rv = self[i,1]
|
405
|
+
self[i,1] = ''
|
406
|
+
rv
|
407
|
+
end
|
408
|
+
|
409
|
+
# Return a random string index.
|
410
|
+
#
|
411
|
+
# "Ruby rules".rand_index #=> 3
|
412
|
+
#
|
413
|
+
def rand_index
|
414
|
+
Random.number(size)
|
415
|
+
end
|
416
|
+
|
417
|
+
# Return the string with seperated sections arranged
|
418
|
+
# in a random order. The default seperation is by character.
|
419
|
+
#
|
420
|
+
# "Ruby rules".shuffle #=> "e lybRsuur"
|
421
|
+
#
|
422
|
+
def shuffle(separator=//)
|
423
|
+
split(separator).shuffle.join('')
|
424
|
+
end
|
425
|
+
|
426
|
+
# In place version of shuffle.
|
427
|
+
#
|
428
|
+
def shuffle!(separator=//)
|
429
|
+
self.replace( shuffle(separator) )
|
430
|
+
end
|
431
|
+
|
432
|
+
end
|
433
|
+
|
434
|
+
end
|
435
|
+
|
436
|
+
class Object
|
437
|
+
include Random
|
438
|
+
end
|
439
|
+
|
440
|
+
class Array
|
441
|
+
include Random
|
442
|
+
end
|
443
|
+
|
444
|
+
class Hash
|
445
|
+
include Random
|
446
|
+
end
|
447
|
+
|
448
|
+
class String
|
449
|
+
include Random
|
450
|
+
end
|
451
|
+
|