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,540 @@
|
|
1
|
+
# = Duration
|
2
|
+
#
|
3
|
+
# Duration is a simple class that provides ways of easily manipulating durations
|
4
|
+
# (timespans) and formatting them as well.
|
5
|
+
#
|
6
|
+
# require 'duration'
|
7
|
+
# => true
|
8
|
+
# d = Duration.new(60 * 60 * 24 * 10 + 120 + 30)
|
9
|
+
# => #<Duration: 1 week, 3 days, 2 minutes and 30 seconds>
|
10
|
+
# d.to_s
|
11
|
+
# => "1 week, 3 days, 2 minutes and 30 seconds"
|
12
|
+
# [d.weeks, d.days]
|
13
|
+
# => [1, 3]
|
14
|
+
# d.days = 7; d
|
15
|
+
# => #<Duration: 2 weeks, 2 minutes and 30 seconds>
|
16
|
+
# d.strftime('%w w, %d d, %h h, %m m, %s s')
|
17
|
+
# => "2 w, 0 d, 0 h, 2 m, 30 s"
|
18
|
+
#
|
19
|
+
# == Author
|
20
|
+
#
|
21
|
+
# * Matthew Harris (mailto:shugotenshi@gmail.com)
|
22
|
+
#
|
23
|
+
# == Notes
|
24
|
+
#
|
25
|
+
# * This library comes from the orginal Duration project.
|
26
|
+
# See: http://www.rubyforge.org/projects/duration
|
27
|
+
#
|
28
|
+
# == Copying
|
29
|
+
#
|
30
|
+
# Copyright (c) 2006 Matthew Harris <shugotenshi at gmail.com>
|
31
|
+
|
32
|
+
# = Duration
|
33
|
+
#
|
34
|
+
# Duration is a simple class that provides ways of easily manipulating durations
|
35
|
+
# (timespans) and formatting them as well.
|
36
|
+
#
|
37
|
+
# require 'duration'
|
38
|
+
# => true
|
39
|
+
# d = Duration.new(60 * 60 * 24 * 10 + 120 + 30)
|
40
|
+
# => #<Duration: 1 week, 3 days, 2 minutes and 30 seconds>
|
41
|
+
# d.to_s
|
42
|
+
# => "1 week, 3 days, 2 minutes and 30 seconds"
|
43
|
+
# [d.weeks, d.days]
|
44
|
+
# => [1, 3]
|
45
|
+
# d.days = 7; d
|
46
|
+
# => #<Duration: 2 weeks, 2 minutes and 30 seconds>
|
47
|
+
# d.strftime('%w w, %d d, %h h, %m m, %s s')
|
48
|
+
# => "2 w, 0 d, 0 h, 2 m, 30 s"
|
49
|
+
|
50
|
+
class Duration
|
51
|
+
include Comparable
|
52
|
+
include Enumerable
|
53
|
+
|
54
|
+
attr_reader :total, :weeks, :days, :hours, :minutes
|
55
|
+
|
56
|
+
WEEK = 60 * 60 * 24 * 7
|
57
|
+
DAY = 60 * 60 * 24
|
58
|
+
HOUR = 60 * 60
|
59
|
+
MINUTE = 60
|
60
|
+
SECOND = 1
|
61
|
+
|
62
|
+
# Initialize Duration class.
|
63
|
+
#
|
64
|
+
# *Example*
|
65
|
+
#
|
66
|
+
# d = Duration.new(60 * 60 * 24 * 10 + 120 + 30)
|
67
|
+
# => #<Duration: 1 week, 3 days, 2 minutes and 30 seconds>
|
68
|
+
# d = Duration.new(:weeks => 1, :days => 3, :minutes => 2, :seconds => 30)
|
69
|
+
# => #<Duration: 1 week, 3 days, 2 minutes and 30 seconds>
|
70
|
+
#
|
71
|
+
def initialize(seconds_or_attr = 0)
|
72
|
+
if seconds_or_attr.kind_of? Hash
|
73
|
+
# Part->time map table.
|
74
|
+
h = {:weeks => WEEK, :days => DAY, :hours => HOUR, :minutes => MINUTE, :seconds => SECOND}
|
75
|
+
|
76
|
+
# Loop through each valid part, ignore all others.
|
77
|
+
seconds = seconds_or_attr.inject(0) do |sec, args|
|
78
|
+
# Grab the part of the duration (week, day, whatever) and the number of seconds for it.
|
79
|
+
part, time = args
|
80
|
+
|
81
|
+
# Map each part to their number of seconds and the given value.
|
82
|
+
# {:weeks => 2} maps to h[:weeks] -- so... weeks = WEEK * 2
|
83
|
+
if h.key?(prt = part.to_s.to_sym) then sec + time * h[prt] else 0 end
|
84
|
+
end
|
85
|
+
else
|
86
|
+
seconds = seconds_or_attr
|
87
|
+
end
|
88
|
+
|
89
|
+
@total, array = seconds.to_f.round, []
|
90
|
+
@seconds = [WEEK, DAY, HOUR, MINUTE].inject(@total) do |left, part|
|
91
|
+
array << left / part; left % part
|
92
|
+
end
|
93
|
+
|
94
|
+
@weeks, @days, @hours, @minutes = array
|
95
|
+
end
|
96
|
+
|
97
|
+
# Format duration.
|
98
|
+
#
|
99
|
+
# *Identifiers*
|
100
|
+
#
|
101
|
+
# %w -- Number of weeks
|
102
|
+
# %d -- Number of days
|
103
|
+
# %h -- Number of hours
|
104
|
+
# %m -- Number of minutes
|
105
|
+
# %s -- Number of seconds
|
106
|
+
# %t -- Total number of seconds
|
107
|
+
# %x -- Duration#to_s
|
108
|
+
# %% -- Literal `%' character
|
109
|
+
#
|
110
|
+
# *Example*
|
111
|
+
#
|
112
|
+
# d = Duration.new(:weeks => 10, :days => 7)
|
113
|
+
# => #<Duration: 11 weeks>
|
114
|
+
# d.strftime("It's been %w weeks!")
|
115
|
+
# => "It's been 11 weeks!"
|
116
|
+
#
|
117
|
+
def strftime(fmt)
|
118
|
+
h =\
|
119
|
+
{'w' => @weeks ,
|
120
|
+
'd' => @days ,
|
121
|
+
'h' => @hours ,
|
122
|
+
'm' => @minutes,
|
123
|
+
's' => @seconds,
|
124
|
+
't' => @total ,
|
125
|
+
'x' => to_s}
|
126
|
+
|
127
|
+
fmt.gsub(/%?%(w|d|h|m|s|t|x)/) do |match|
|
128
|
+
match.size == 3 ? match : h[match[1..1]]
|
129
|
+
end.gsub('%%', '%')
|
130
|
+
end
|
131
|
+
|
132
|
+
# Get the number of seconds of a given part, or simply just get the number of
|
133
|
+
# seconds.
|
134
|
+
#
|
135
|
+
# *Example*
|
136
|
+
#
|
137
|
+
# d = Duration.new(:weeks => 1, :days => 1, :hours => 1, :seconds => 30)
|
138
|
+
# => #<Duration: 1 week, 1 day, 1 hour and 30 seconds>
|
139
|
+
# d.seconds(:weeks)
|
140
|
+
# => 604800
|
141
|
+
# d.seconds(:days)
|
142
|
+
# => 86400
|
143
|
+
# d.seconds(:hours)
|
144
|
+
# => 3600
|
145
|
+
# d.seconds
|
146
|
+
# => 30
|
147
|
+
#
|
148
|
+
def seconds(part = nil)
|
149
|
+
# Table mapping
|
150
|
+
h = {:weeks => WEEK, :days => DAY, :hours => HOUR, :minutes => MINUTE}
|
151
|
+
|
152
|
+
if [:weeks, :days, :hours, :minutes].include? part
|
153
|
+
__send__(part) * h[part]
|
154
|
+
else
|
155
|
+
@seconds
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# For iterating through the duration set of weeks, days, hours, minutes, and
|
160
|
+
# seconds.
|
161
|
+
#
|
162
|
+
# *Example*
|
163
|
+
#
|
164
|
+
# Duration.new(:weeks => 1, :seconds => 30).each do |part, time|
|
165
|
+
# puts "part: #{part}, time: #{time}"
|
166
|
+
# end
|
167
|
+
#
|
168
|
+
# _Output_
|
169
|
+
#
|
170
|
+
# part: weeks, time: 1
|
171
|
+
# part: days, time: 0
|
172
|
+
# part: hours, time: 0
|
173
|
+
# part: minutes, time: 0
|
174
|
+
# part: seconds, time: 30
|
175
|
+
#
|
176
|
+
def each
|
177
|
+
[['weeks' , @weeks ],
|
178
|
+
['days' , @days ],
|
179
|
+
['hours' , @hours ],
|
180
|
+
['minutes' , @minutes],
|
181
|
+
['seconds' , @seconds]].each do |part, time|
|
182
|
+
# Yield to block
|
183
|
+
yield part, time
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Calls `<=>' on Duration#total.
|
188
|
+
#
|
189
|
+
# *Example*
|
190
|
+
#
|
191
|
+
# 5.days == 24.hours * 5
|
192
|
+
# => true
|
193
|
+
#
|
194
|
+
def <=>(other)
|
195
|
+
@total <=> other.to_i
|
196
|
+
end
|
197
|
+
|
198
|
+
# Set the number of weeks.
|
199
|
+
#
|
200
|
+
# *Example*
|
201
|
+
#
|
202
|
+
# d = Duration.new(0)
|
203
|
+
# => #<Duration: ...>
|
204
|
+
# d.weeks = 2; d
|
205
|
+
# => #<Duration: 2 weeks>
|
206
|
+
#
|
207
|
+
def weeks=(n)
|
208
|
+
initialize(:weeks => n, :seconds => @total - seconds(:weeks))
|
209
|
+
end
|
210
|
+
|
211
|
+
# Set the number of days.
|
212
|
+
#
|
213
|
+
# *Example*
|
214
|
+
#
|
215
|
+
# d = Duration.new(0)
|
216
|
+
# => #<Duration: ...>
|
217
|
+
# d.days = 5; d
|
218
|
+
# => #<Duration: 5 days>
|
219
|
+
#
|
220
|
+
def days=(n)
|
221
|
+
initialize(:days => n, :seconds => @total - seconds(:days))
|
222
|
+
end
|
223
|
+
|
224
|
+
# Set the number of hours.
|
225
|
+
#
|
226
|
+
# *Example*
|
227
|
+
#
|
228
|
+
# d = Duration.new(0)
|
229
|
+
# => #<Duration: ...>
|
230
|
+
# d.hours = 5; d
|
231
|
+
# => #<Duration: 5 hours>
|
232
|
+
#
|
233
|
+
def hours=(n)
|
234
|
+
initialize(:hours => n, :seconds => @total - seconds(:hours))
|
235
|
+
end
|
236
|
+
|
237
|
+
# Set the number of minutes.
|
238
|
+
#
|
239
|
+
# *Example*
|
240
|
+
#
|
241
|
+
# d = Duration.new(0)
|
242
|
+
# => #<Duration: ...>
|
243
|
+
# d.minutes = 30; d
|
244
|
+
# => #<Duration: 30 minutes>
|
245
|
+
#
|
246
|
+
def minutes=(n)
|
247
|
+
initialize(:minutes => n, :seconds => @total - seconds(:minutes))
|
248
|
+
end
|
249
|
+
|
250
|
+
# Set the number of minutes.
|
251
|
+
#
|
252
|
+
# *Example*
|
253
|
+
#
|
254
|
+
# d = Duration.new(0)
|
255
|
+
# => #<Duration: ...>
|
256
|
+
# d.seconds = 30; d
|
257
|
+
# => #<Duration: 30 seconds>
|
258
|
+
#
|
259
|
+
def seconds=(n)
|
260
|
+
initialize(:seconds => (@total + n) - @seconds)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Friendly, human-readable string representation of the duration.
|
264
|
+
#
|
265
|
+
# *Example*
|
266
|
+
#
|
267
|
+
# d = Duration.new(:seconds => 140)
|
268
|
+
# => #<Duration: 2 minutes and 20 seconds>
|
269
|
+
# d.to_s
|
270
|
+
# => "2 minutes and 20 seconds"
|
271
|
+
#
|
272
|
+
def to_s
|
273
|
+
str = ''
|
274
|
+
|
275
|
+
each do |part, time|
|
276
|
+
# Skip any zero times.
|
277
|
+
next if time.zero?
|
278
|
+
|
279
|
+
# Concatenate the part of the time and the time itself.
|
280
|
+
str << "#{time} #{time == 1 ? part[0..-2] : part}, "
|
281
|
+
end
|
282
|
+
|
283
|
+
str.chomp(', ').sub(/(.+), (.+)/, '\1 and \2')
|
284
|
+
end
|
285
|
+
|
286
|
+
# Inspection string--Similar to #to_s except that it has the class name.
|
287
|
+
#
|
288
|
+
# *Example*
|
289
|
+
#
|
290
|
+
# Duration.new(:seconds => 140)
|
291
|
+
# => #<Duration: 2 minutes and 20 seconds>
|
292
|
+
#
|
293
|
+
def inspect
|
294
|
+
"#<#{self.class}: #{(s = to_s).empty? ? '...' : s}>"
|
295
|
+
end
|
296
|
+
|
297
|
+
# Add to Duration.
|
298
|
+
#
|
299
|
+
# *Example*
|
300
|
+
#
|
301
|
+
# d = Duration.new(30)
|
302
|
+
# => #<Duration: 30 seconds>
|
303
|
+
# d + 30
|
304
|
+
# => #<Duration: 1 minute>
|
305
|
+
#
|
306
|
+
def +(other)
|
307
|
+
self.class.new(@total + other.to_i)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Subtract from Duration.
|
311
|
+
#
|
312
|
+
# *Example*
|
313
|
+
#
|
314
|
+
# d = Duration.new(30)
|
315
|
+
# => #<Duration: 30 seconds>
|
316
|
+
# d - 15
|
317
|
+
# => #<Duration: 15 seconds>
|
318
|
+
#
|
319
|
+
def -(other)
|
320
|
+
self.class.new(@total - other.to_i)
|
321
|
+
end
|
322
|
+
|
323
|
+
# Multiply two Durations.
|
324
|
+
#
|
325
|
+
# *Example*
|
326
|
+
#
|
327
|
+
# d = Duration.new(30)
|
328
|
+
# => #<Duration: 30 seconds>
|
329
|
+
# d * 2
|
330
|
+
# => #<Duration: 1 minute>
|
331
|
+
#
|
332
|
+
def *(other)
|
333
|
+
self.class.new(@total * other.to_i)
|
334
|
+
end
|
335
|
+
|
336
|
+
# Divide two Durations.
|
337
|
+
#
|
338
|
+
# *Example*
|
339
|
+
#
|
340
|
+
# d = Duration.new(30)
|
341
|
+
# => #<Duration: 30 seconds>
|
342
|
+
# d / 2
|
343
|
+
# => #<Duration: 15 seconds>
|
344
|
+
#
|
345
|
+
def /(other)
|
346
|
+
self.class.new(@total / other.to_i)
|
347
|
+
end
|
348
|
+
|
349
|
+
alias to_i total
|
350
|
+
end
|
351
|
+
|
352
|
+
# BigDuration is a variant of Duration that supports years and months. Support
|
353
|
+
# for months is not accurate, as a month is assumed to be 30 days so use at your
|
354
|
+
# own risk.
|
355
|
+
#
|
356
|
+
class BigDuration < Duration
|
357
|
+
attr_reader :years, :months
|
358
|
+
|
359
|
+
YEAR = 60 * 60 * 24 * 30 * 12
|
360
|
+
MONTH = 60 * 60 * 24 * 30
|
361
|
+
|
362
|
+
# Similar to Duration.new except that BigDuration.new supports `:years' and
|
363
|
+
# `:months' and will also handle years and months correctly when breaking down
|
364
|
+
# the seconds.
|
365
|
+
#
|
366
|
+
def initialize(seconds_or_attr = 0)
|
367
|
+
if seconds_or_attr.kind_of? Hash
|
368
|
+
# Part->time map table.
|
369
|
+
h =\
|
370
|
+
{:years => YEAR ,
|
371
|
+
:months => MONTH ,
|
372
|
+
:weeks => WEEK ,
|
373
|
+
:days => DAY ,
|
374
|
+
:hours => HOUR ,
|
375
|
+
:minutes => MINUTE,
|
376
|
+
:seconds => SECOND}
|
377
|
+
|
378
|
+
# Loop through each valid part, ignore all others.
|
379
|
+
seconds = seconds_or_attr.inject(0) do |sec, args|
|
380
|
+
# Grab the part of the duration (week, day, whatever) and the number of seconds for it.
|
381
|
+
part, time = args
|
382
|
+
|
383
|
+
# Map each part to their number of seconds and the given value.
|
384
|
+
# {:weeks => 2} maps to h[:weeks] -- so... weeks = WEEK * 2
|
385
|
+
if h.key?(prt = part.to_s.to_sym) then sec + time * h[prt] else 0 end
|
386
|
+
end
|
387
|
+
else
|
388
|
+
seconds = seconds_or_attr
|
389
|
+
end
|
390
|
+
|
391
|
+
@total, array = seconds.to_f.round, []
|
392
|
+
@seconds = [YEAR, MONTH, WEEK, DAY, HOUR, MINUTE].inject(@total) do |left, part|
|
393
|
+
array << left / part; left % part
|
394
|
+
end
|
395
|
+
|
396
|
+
@years, @months, @weeks, @days, @hours, @minutes = array
|
397
|
+
end
|
398
|
+
|
399
|
+
# BigDuration variant of Duration#strftime.
|
400
|
+
#
|
401
|
+
# *Identifiers: BigDuration*
|
402
|
+
#
|
403
|
+
# %y -- Number of years
|
404
|
+
# %m -- Number of months
|
405
|
+
#
|
406
|
+
def strftime(fmt)
|
407
|
+
h = {'y' => @years, 'M' => @months}
|
408
|
+
super(fmt.gsub(/%?%(y|M)/) { |match| match.size == 3 ? match : h[match[1..1]] })
|
409
|
+
end
|
410
|
+
|
411
|
+
# Similar to Duration#each except includes years and months in the interation.
|
412
|
+
#
|
413
|
+
def each
|
414
|
+
[['years' , @years ],
|
415
|
+
['months' , @months ],
|
416
|
+
['weeks' , @weeks ],
|
417
|
+
['days' , @days ],
|
418
|
+
['hours' , @hours ],
|
419
|
+
['minutes' , @minutes],
|
420
|
+
['seconds' , @seconds]].each do |part, time|
|
421
|
+
# Yield to block
|
422
|
+
yield part, time
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
# Derived from Duration#seconds, but supports `:years' and `:months' as well.
|
427
|
+
#
|
428
|
+
def seconds(part = nil)
|
429
|
+
h = {:years => YEAR, :months => MONTH}
|
430
|
+
if [:years, :months].include? part
|
431
|
+
__send__(part) * h[part]
|
432
|
+
else
|
433
|
+
super(part)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
# Set the number of years in the BigDuration.
|
438
|
+
#
|
439
|
+
def years=(n)
|
440
|
+
initialize(:years => n, :seconds => @total - seconds(:years))
|
441
|
+
end
|
442
|
+
|
443
|
+
# Set the number of months in the BigDuration.
|
444
|
+
#
|
445
|
+
def months=(n)
|
446
|
+
initialize(:months => n, :seconds => @total - seconds(:months))
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
# The following important additions are made to Numeric:
|
451
|
+
#
|
452
|
+
# Numeric#weeks -- Create a Duration object with given weeks
|
453
|
+
# Numeric#days -- Create a Duration object with given days
|
454
|
+
# Numeric#hours -- Create a Duration object with given hours
|
455
|
+
# Numeric#minutes -- Create a Duration object with given minutes
|
456
|
+
# Numeric#seconds -- Create a Duration object with given seconds
|
457
|
+
#
|
458
|
+
# BigDuration support:
|
459
|
+
#
|
460
|
+
# Numeric#years -- Create a BigDuration object with given years
|
461
|
+
# Numeric#months -- Create a BigDuration object with given months
|
462
|
+
#
|
463
|
+
# BigDuration objects can be created from regular weeks, days, hours, etc by
|
464
|
+
# providing `:big' as an argument to the above Numeric methods.
|
465
|
+
|
466
|
+
#
|
467
|
+
class Numeric
|
468
|
+
# Create a Duration object using self where self could represent weeks, days,
|
469
|
+
# hours, minutes, and seconds.
|
470
|
+
#
|
471
|
+
# *Example*
|
472
|
+
#
|
473
|
+
# 10.duration(:weeks)
|
474
|
+
# => #<Duration: 10 weeks>
|
475
|
+
# 10.duration
|
476
|
+
# => #<Duration: 10 seconds>
|
477
|
+
#
|
478
|
+
def duration(part = nil, klass = Duration)
|
479
|
+
if [:years, :months, :weeks, :days, :hours, :minutes, :seconds].include? part
|
480
|
+
klass.new(part => self)
|
481
|
+
else
|
482
|
+
klass.new(self)
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
# TODO: IF WE WANT TO DO THIS IT NEEDS TO BE ADDED TO times.rb ???
|
487
|
+
#
|
488
|
+
# alias __numeric_old_method_missing method_missing
|
489
|
+
#
|
490
|
+
# # Intercept calls to .weeks, .days, .hours, .minutes and .seconds because
|
491
|
+
# # Rails defines its own methods, so I'd like to prevent any redefining of
|
492
|
+
# # Rails' methods. If these methods don't get captured, then alternatively
|
493
|
+
# # Numeric#duration can be used.
|
494
|
+
# #
|
495
|
+
# # BigDuration methods include .years and .months, also BigDuration objects
|
496
|
+
# # can be created from any time such as weeks or minutes and even seconds.
|
497
|
+
# #
|
498
|
+
# # *Example: BigDuration*
|
499
|
+
# #
|
500
|
+
# # 5.years
|
501
|
+
# # => #<BigDuration: 5 years>
|
502
|
+
# # 10.minutes(:big)
|
503
|
+
# # => #<BigDuration: 10 minutes>
|
504
|
+
# #
|
505
|
+
# # *Example*
|
506
|
+
# #
|
507
|
+
# # 140.seconds
|
508
|
+
# # => #<Duration: 2 minutes and 20 seconds>
|
509
|
+
# #
|
510
|
+
# def method_missing(method, *args)
|
511
|
+
# if [:weeks, :days, :hours, :minutes, :seconds].include? method
|
512
|
+
# if args.size > 0 && args[0] == :big
|
513
|
+
# duration(method, BigDuration)
|
514
|
+
# else
|
515
|
+
# duration(method)
|
516
|
+
# end
|
517
|
+
# elsif [:years, :months].include? method
|
518
|
+
# duration(method, BigDuration)
|
519
|
+
# else
|
520
|
+
# __numeric_old_method_missing(method, *args)
|
521
|
+
# end
|
522
|
+
# end
|
523
|
+
|
524
|
+
end
|
525
|
+
|
526
|
+
# Time#duration has been added to convert the UNIX timestamp into a Duration.
|
527
|
+
# See Time#duration for an example.
|
528
|
+
#
|
529
|
+
class Time
|
530
|
+
# Create a Duration object from the UNIX timestamp.
|
531
|
+
#
|
532
|
+
# *Example*
|
533
|
+
#
|
534
|
+
# Time.now.duration
|
535
|
+
# => #<Duration: 1898 weeks, 6 days, 1 hour, 12 minutes and 1 second>
|
536
|
+
#
|
537
|
+
def duration(type = nil)
|
538
|
+
if type == :big then BigDuration.new(to_i) else Duration.new(to_i) end
|
539
|
+
end
|
540
|
+
end
|