facets 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/NOTES +7 -1
- data/lib/core/facets/array.rb +6 -6
- data/lib/{methods → core}/facets/array/contains.rb +0 -0
- data/lib/{methods → core}/facets/array/delete_unless.rb +0 -0
- data/lib/{methods → core}/facets/array/delete_values.rb +0 -0
- data/lib/{methods → core}/facets/array/delete_values_at.rb +0 -0
- data/lib/{methods → core}/facets/array/each_iteration.rb +0 -0
- data/lib/{methods → core}/facets/array/first.rb +0 -0
- data/lib/{methods → core}/facets/array/join_sentence.rb +0 -0
- data/lib/{methods → core}/facets/array/last.rb +0 -0
- data/lib/{methods → core}/facets/array/poke.rb +0 -0
- data/lib/{methods → core}/facets/array/pull.rb +0 -0
- data/lib/{methods → core}/facets/array/store.rb +0 -0
- data/lib/{methods → core}/facets/array/to_b.rb +0 -0
- data/lib/{methods → core}/facets/array/to_h.rb +0 -0
- data/lib/{methods → core}/facets/array/to_path.rb +0 -0
- data/lib/core/facets/binding.rb +3 -2
- data/lib/core/facets/binding/__DIR__.rb +1 -0
- data/lib/core/facets/binding/__FILE__.rb +1 -0
- data/lib/core/facets/binding/__LINE__.rb +1 -0
- data/lib/core/facets/binding/__callee__.rb +1 -0
- data/lib/core/facets/binding/__method__.rb +1 -0
- data/lib/core/facets/binding/call_stack.rb +1 -0
- data/lib/core/facets/binding/called.rb +1 -0
- data/lib/core/facets/binding/{cflow.rb → caller.rb} +19 -14
- data/lib/core/facets/binding/here.rb +1 -9
- data/lib/{methods → core}/facets/binding/included.rb +0 -0
- data/lib/{methods → core}/facets/binding/local_variables.rb +0 -0
- data/lib/core/facets/binding/methodname.rb +1 -0
- data/lib/{methods → core}/facets/binding/op_fetch.rb +0 -0
- data/lib/core/facets/binding/self.rb +2 -0
- data/lib/core/facets/class.rb +4 -0
- data/lib/{methods → core}/facets/class/cattr.rb +0 -0
- data/lib/{methods → core}/facets/class/cattr_accessor.rb +0 -0
- data/lib/{methods → core}/facets/class/cattr_reader.rb +0 -0
- data/lib/{methods → core}/facets/class/cattr_writer.rb +0 -0
- data/lib/{methods → core}/facets/class/class_load.rb +0 -0
- data/lib/{methods → core}/facets/class/class_require.rb +0 -0
- data/lib/{methods → core}/facets/class/mattr.rb +0 -0
- data/lib/{methods → core}/facets/class/mattr_accessor.rb +0 -0
- data/lib/{methods → core}/facets/class/mattr_reader.rb +0 -0
- data/lib/{methods → core}/facets/class/mattr_writer.rb +0 -0
- data/lib/core/facets/class/remove_descendents.rb +19 -0
- data/lib/core/facets/class/remove_subclasses.rb +1 -0
- data/lib/{methods → core}/facets/class/subclasses.rb +0 -0
- data/lib/{methods → core}/facets/class/to_proc.rb +0 -0
- data/lib/{methods → core}/facets/comparable/at_least.rb +0 -0
- data/lib/{methods → core}/facets/comparable/at_most.rb +0 -0
- data/lib/{methods → core}/facets/comparable/cap.rb +0 -0
- data/lib/{methods → core}/facets/comparable/clip.rb +0 -0
- data/lib/core/facets/comparable/cmp.rb +1 -1
- data/lib/core/facets/conversion.rb +0 -10
- data/lib/core/facets/dir.rb +2 -0
- data/lib/{methods → core}/facets/dir/ancestor.rb +0 -0
- data/lib/{methods → core}/facets/dir/ascend.rb +0 -0
- data/lib/{methods → core}/facets/dir/descend.rb +0 -0
- data/lib/core/facets/dir/ls_r.rb +1 -0
- data/lib/{methods → core}/facets/dir/multiglob_r.rb +0 -0
- data/lib/core/facets/dir/parent.rb +12 -0
- data/lib/core/facets/dir/recurse.rb +28 -0
- data/lib/core/facets/dir/traverse.rb +1 -43
- data/lib/{methods → core}/facets/enumerable/cart.rb +0 -0
- data/lib/core/facets/enumerable/cartesian.rb +0 -45
- data/lib/{methods → core}/facets/enumerable/cartesian_product.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/cluster_by.rb +0 -0
- data/lib/core/facets/enumerable/collate.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/collect_if.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/collect_with_index.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/combinations.rb +0 -0
- data/lib/core/facets/enumerable/combos.rb +48 -0
- data/lib/{methods → core}/facets/enumerable/commonality.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/compact_collect.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/compact_map.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/divide.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/duplicates.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/each_by.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/each_combination.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/each_combo.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/each_pair.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/each_permutation.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/each_unique_pair.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/eachn.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/entropy.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/filter_collect.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/filter_map.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/frequency.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/graph.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/group_by.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/ideal_entropy.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/inject.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/injecting.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/map_if.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/map_send.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/map_with_index.rb +0 -0
- data/lib/core/facets/enumerable/mash.rb +1 -9
- data/lib/{methods → core}/facets/enumerable/mode.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/modulate.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/none.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/nonuniq.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/occur.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/one.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/op_pow.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/partition_by.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/permutation_number.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/permute.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/sum.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/to_h.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/to_hash.rb +0 -0
- data/lib/{methods → core}/facets/enumerable/uniq_by.rb +0 -0
- data/lib/core/facets/file.rb +4 -1
- data/lib/core/facets/file/append.rb +1 -0
- data/lib/core/facets/file/create.rb +1 -0
- data/lib/core/facets/file/null.rb +20 -0
- data/lib/{methods → core}/facets/file/read_binary.rb +0 -0
- data/lib/{methods → core}/facets/file/read_list.rb +0 -0
- data/lib/core/facets/file/rewrite.rb +1 -0
- data/lib/core/facets/file/rootname.rb +22 -0
- data/lib/core/facets/file/sanitize.rb +14 -0
- data/lib/core/facets/file/split_all.rb +19 -0
- data/lib/core/facets/file/writelines.rb +1 -0
- data/lib/{methods → core}/facets/float/round_at.rb +0 -0
- data/lib/{methods → core}/facets/float/round_off.rb +0 -0
- data/lib/{methods → core}/facets/float/round_to.rb +0 -0
- data/lib/core/facets/hash.rb +20 -12
- data/lib/core/facets/hash/alias.rb +28 -0
- data/lib/core/facets/hash/at.rb +0 -7
- data/lib/core/facets/hash/{new.rb → autonew.rb} +0 -15
- data/lib/core/facets/hash/collate.rb +44 -0
- data/lib/{methods → core}/facets/hash/delete_at.rb +0 -0
- data/lib/{methods → core}/facets/hash/delete_unless.rb +0 -0
- data/lib/{methods → core}/facets/hash/delete_values.rb +0 -0
- data/lib/{methods → core}/facets/hash/delete_values_at.rb +0 -0
- data/lib/core/facets/hash/diff.rb +15 -0
- data/lib/core/facets/hash/each_with_key.rb +12 -0
- data/lib/core/facets/hash/except.rb +23 -0
- data/lib/{methods → core}/facets/hash/graph.rb +0 -0
- data/lib/{methods → core}/facets/hash/has_only_keys.rb +0 -0
- data/lib/core/facets/hash/join.rb +14 -0
- data/lib/{methods → core}/facets/hash/mash.rb +0 -0
- data/lib/core/facets/hash/op.rb +0 -12
- data/lib/{methods → core}/facets/hash/op_and.rb +0 -0
- data/lib/core/facets/hash/op_div.rb +10 -0
- data/lib/{methods → core}/facets/hash/op_lshift.rb +0 -0
- data/lib/{methods → core}/facets/hash/op_minus.rb +0 -0
- data/lib/{methods → core}/facets/hash/op_mul.rb +0 -0
- data/lib/{methods → core}/facets/hash/op_or.rb +0 -0
- data/lib/{methods → core}/facets/hash/op_plus.rb +0 -0
- data/lib/core/facets/hash/pairs_at.rb +15 -0
- data/lib/core/facets/hash/rekey.rb +33 -70
- data/lib/{methods → core}/facets/hash/replace_each.rb +0 -0
- data/lib/core/facets/hash/{merge.rb → reverse_merge.rb} +0 -0
- data/lib/core/facets/hash/reverse_update.rb +1 -0
- data/lib/core/facets/hash/slice.rb +0 -19
- data/lib/core/facets/hash/swap.rb +36 -0
- data/lib/{methods → core}/facets/hash/to_h.rb +0 -0
- data/lib/{methods → core}/facets/hash/to_proc.rb +0 -0
- data/lib/{methods → core}/facets/hash/to_proc_with_reponse.rb +0 -0
- data/lib/{methods → core}/facets/hash/to_struct.rb +0 -0
- data/lib/core/facets/hash/update.rb +16 -6
- data/lib/{methods → core}/facets/hash/update_each.rb +0 -0
- data/lib/{methods → core}/facets/hash/update_keys.rb +0 -0
- data/lib/{methods → core}/facets/hash/update_values.rb +0 -0
- data/lib/core/facets/hash/zipnew.rb +18 -0
- data/lib/core/facets/integer.rb +2 -2
- data/lib/{methods → core}/facets/integer/bit.rb +0 -0
- data/lib/{methods → core}/facets/integer/clear_bit.rb +0 -0
- data/lib/core/facets/integer/even.rb +1 -0
- data/lib/{methods → core}/facets/integer/fac.rb +0 -0
- data/lib/core/facets/integer/{multiples.rb → multiple.rb} +0 -0
- data/lib/core/facets/integer/odd.rb +1 -0
- data/lib/{methods → core}/facets/integer/times_collect.rb +0 -0
- data/lib/{methods → core}/facets/integer/times_map.rb +0 -0
- data/lib/{methods → core}/facets/kernel/Bit.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__DIR__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__assign__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__callee__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__class__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__get__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__method__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__real__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__set__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/__singleton_class__.rb +0 -0
- data/lib/{methods → core}/facets/kernel/as.rb +0 -0
- data/lib/{methods → core}/facets/kernel/assign_from.rb +0 -0
- data/lib/{methods → core}/facets/kernel/assign_with.rb +0 -0
- data/lib/{methods → core}/facets/kernel/bitmask.rb +0 -0
- data/lib/{methods → core}/facets/kernel/bool.rb +0 -0
- data/lib/{methods → core}/facets/kernel/call_stack.rb +0 -0
- data/lib/{methods → core}/facets/kernel/called.rb +0 -0
- data/lib/{methods → core}/facets/kernel/callee.rb +0 -0
- data/lib/{methods → core}/facets/kernel/class_def.rb +0 -0
- data/lib/{methods → core}/facets/kernel/complete.rb +0 -0
- data/lib/{methods → core}/facets/kernel/copy.rb +0 -0
- data/lib/{methods → core}/facets/kernel/d.rb +0 -0
- data/lib/{methods → core}/facets/kernel/deep_clone.rb +0 -0
- data/lib/{methods → core}/facets/kernel/deep_copy.rb +0 -0
- data/lib/{methods → core}/facets/kernel/demo.rb +0 -0
- data/lib/{methods → core}/facets/kernel/eigenclass.rb +0 -0
- data/lib/{methods → core}/facets/kernel/enable_warnings.rb +0 -0
- data/lib/{methods → core}/facets/kernel/false.rb +0 -0
- data/lib/{methods → core}/facets/kernel/fn.rb +0 -0
- data/lib/core/facets/kernel/here.rb +9 -0
- data/lib/{methods → core}/facets/kernel/in.rb +0 -0
- data/lib/{methods → core}/facets/kernel/instance_assign.rb +0 -0
- data/lib/{methods → core}/facets/kernel/instance_assume.rb +0 -0
- data/lib/{methods → core}/facets/kernel/instance_class.rb +0 -0
- data/lib/{methods → core}/facets/kernel/instance_exec.rb +0 -0
- data/lib/{methods → core}/facets/kernel/instance_send.rb +0 -0
- data/lib/{methods → core}/facets/kernel/instance_values.rb +0 -0
- data/lib/{methods → core}/facets/kernel/is.rb +0 -0
- data/lib/{methods → core}/facets/kernel/load_local.rb +0 -0
- data/lib/{methods → core}/facets/kernel/meta.rb +0 -0
- data/lib/{methods → core}/facets/kernel/meta_alias.rb +0 -0
- data/lib/{methods → core}/facets/kernel/meta_class.rb +0 -0
- data/lib/{methods → core}/facets/kernel/meta_def.rb +0 -0
- data/lib/{methods → core}/facets/kernel/meta_eval.rb +0 -0
- data/lib/{methods → core}/facets/kernel/metaclass.rb +0 -0
- data/lib/{methods → core}/facets/kernel/method.rb +0 -0
- data/lib/{methods → core}/facets/kernel/non_nil.rb +0 -0
- data/lib/{methods → core}/facets/kernel/not_nil.rb +0 -0
- data/lib/{methods → core}/facets/kernel/object_class.rb +0 -0
- data/lib/{methods → core}/facets/kernel/object_clone.rb +0 -0
- data/lib/{methods → core}/facets/kernel/object_dup.rb +0 -0
- data/lib/{methods → core}/facets/kernel/object_hexid.rb +0 -0
- data/lib/{methods → core}/facets/kernel/object_send.rb +0 -0
- data/lib/{methods → core}/facets/kernel/p.rb +0 -0
- data/lib/{methods → core}/facets/kernel/pp_call_stack.rb +0 -0
- data/lib/{methods → core}/facets/kernel/pp_exception.rb +0 -0
- data/lib/{methods → core}/facets/kernel/qua_class.rb +0 -0
- data/lib/{methods → core}/facets/kernel/require_all.rb +0 -0
- data/lib/{methods → core}/facets/kernel/require_local.rb +0 -0
- data/lib/{methods → core}/facets/kernel/resc.rb +0 -0
- data/lib/{methods → core}/facets/kernel/respond_with_value.rb +0 -0
- data/lib/{methods → core}/facets/kernel/send_as.rb +0 -0
- data/lib/{methods → core}/facets/kernel/set_from.rb +0 -0
- data/lib/{methods → core}/facets/kernel/set_with.rb +0 -0
- data/lib/{methods → core}/facets/kernel/silence_stderr.rb +0 -0
- data/lib/{methods → core}/facets/kernel/silence_stream.rb +0 -0
- data/lib/{methods → core}/facets/kernel/silence_warnings.rb +0 -0
- data/lib/{methods → core}/facets/kernel/singleton.rb +0 -0
- data/lib/{methods → core}/facets/kernel/singleton_class.rb +0 -0
- data/lib/{methods → core}/facets/kernel/super_at.rb +0 -0
- data/lib/{methods → core}/facets/kernel/super_method.rb +0 -0
- data/lib/{methods → core}/facets/kernel/superior.rb +0 -0
- data/lib/{methods → core}/facets/kernel/supermethod.rb +0 -0
- data/lib/{methods → core}/facets/kernel/suppress.rb +0 -0
- data/lib/{methods → core}/facets/kernel/this.rb +0 -0
- data/lib/{methods → core}/facets/kernel/to_b.rb +0 -0
- data/lib/{methods/facets/falseclass → core/facets/kernel}/to_bool.rb +0 -0
- data/lib/{methods → core}/facets/kernel/true.rb +0 -0
- data/lib/{methods → core}/facets/kernel/warn_with_line.rb +0 -0
- data/lib/{methods → core}/facets/kernel/with.rb +0 -0
- data/lib/{methods/facets/object → core/facets/kernel}/with_accessor.rb +0 -0
- data/lib/{methods/facets/object → core/facets/kernel}/with_reader.rb +0 -0
- data/lib/{methods/facets/object → core/facets/kernel}/with_writer.rb +0 -0
- data/lib/core/facets/matchdata.rb +1 -0
- data/lib/core/facets/matchdata/match.rb +16 -0
- data/lib/core/facets/matchdata/matchset.rb +0 -13
- data/lib/{methods → core}/facets/matchdata/matchtree.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_accessor.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_method_chain.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_module_function.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_reader.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_setter.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_switcher.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_tester.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_toggler.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_validator.rb +0 -0
- data/lib/{methods → core}/facets/module/alias_writer.rb +0 -0
- data/lib/{methods → core}/facets/module/all_instance_methods.rb +0 -0
- data/lib/{methods → core}/facets/module/ancestor.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_accessor.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_reader.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_setter.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_switcher.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_tester.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_toggler.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_validator.rb +0 -0
- data/lib/{methods → core}/facets/module/attr_writer.rb +0 -0
- data/lib/{methods → core}/facets/module/basename.rb +0 -0
- data/lib/{methods → core}/facets/module/by_name.rb +0 -0
- data/lib/{methods → core}/facets/module/can.rb +0 -0
- data/lib/{methods → core}/facets/module/class.rb +0 -0
- data/lib/{methods → core}/facets/module/class_def.rb +0 -0
- data/lib/{methods → core}/facets/module/clone_removing.rb +0 -0
- data/lib/{methods → core}/facets/module/clone_renaming.rb +0 -0
- data/lib/{methods → core}/facets/module/clone_using.rb +0 -0
- data/lib/{methods → core}/facets/module/conflict.rb +0 -0
- data/lib/{methods → core}/facets/module/dirname.rb +0 -0
- data/lib/{methods → core}/facets/module/include_and_extend.rb +0 -0
- data/lib/{methods → core}/facets/module/include_as.rb +0 -0
- data/lib/{methods → core}/facets/module/include_function_module.rb +0 -0
- data/lib/{methods → core}/facets/module/instance_method.rb +0 -0
- data/lib/{methods → core}/facets/module/instance_method_defined.rb +0 -0
- data/lib/{methods → core}/facets/module/integrate.rb +0 -0
- data/lib/{methods → core}/facets/module/is.rb +0 -0
- data/lib/{methods → core}/facets/module/modspace.rb +0 -0
- data/lib/{methods → core}/facets/module/module_load.rb +0 -0
- data/lib/{methods → core}/facets/module/module_method.rb +0 -0
- data/lib/{methods → core}/facets/module/module_method_defined.rb +0 -0
- data/lib/{methods → core}/facets/module/module_require.rb +0 -0
- data/lib/{methods → core}/facets/module/nesting.rb +0 -0
- data/lib/{methods → core}/facets/module/nodef.rb +0 -0
- data/lib/{methods → core}/facets/module/on_included.rb +0 -0
- data/lib/{methods → core}/facets/module/op_minus.rb +0 -0
- data/lib/{methods → core}/facets/module/op_mul.rb +0 -0
- data/lib/{methods → core}/facets/module/op_plus.rb +0 -0
- data/lib/{methods → core}/facets/module/private_conflict.rb +0 -0
- data/lib/{methods → core}/facets/module/protected_conflict.rb +0 -0
- data/lib/{methods → core}/facets/module/public_conflict.rb +0 -0
- data/lib/{methods → core}/facets/module/redef.rb +0 -0
- data/lib/{methods → core}/facets/module/redefine_method.rb +0 -0
- data/lib/{methods → core}/facets/module/redirect.rb +0 -0
- data/lib/{methods → core}/facets/module/redirect_method.rb +0 -0
- data/lib/{methods → core}/facets/module/remove.rb +0 -0
- data/lib/{methods → core}/facets/module/rename.rb +0 -0
- data/lib/{methods → core}/facets/module/rename_method.rb +0 -0
- data/lib/{methods → core}/facets/module/revisal.rb +0 -0
- data/lib/{methods → core}/facets/module/wrap.rb +0 -0
- data/lib/{methods → core}/facets/module/wrap_method.rb +0 -0
- data/lib/core/facets/nilclass.rb +1 -0
- data/lib/{methods → core}/facets/nilclass/ergo.rb +0 -0
- data/lib/{methods → core}/facets/nilclass/to_bool.rb +0 -0
- data/lib/{methods → core}/facets/nilclass/to_f.rb +0 -0
- data/lib/{methods → core}/facets/nilclass/to_h.rb +0 -0
- data/lib/core/facets/numeric.rb +1 -0
- data/lib/{methods → core}/facets/numeric/approx.rb +0 -0
- data/lib/{methods → core}/facets/numeric/distance.rb +0 -0
- data/lib/{methods → core}/facets/numeric/pred.rb +0 -0
- data/lib/{methods/facets/integer → core/facets/numeric}/round_at.rb +0 -0
- data/lib/{methods/facets/integer → core/facets/numeric}/round_to.rb +0 -0
- data/lib/{methods → core}/facets/numeric/succ.rb +0 -0
- data/lib/{methods → core}/facets/numeric/to_b.rb +0 -0
- data/lib/core/facets/proc.rb +2 -1
- data/lib/core/facets/proc/compose.rb +0 -6
- data/lib/{methods → core}/facets/proc/op_mul.rb +0 -0
- data/lib/{methods → core}/facets/proc/to_h.rb +0 -0
- data/lib/{methods → core}/facets/proc/to_method.rb +0 -0
- data/lib/core/facets/proc/update.rb +9 -0
- data/lib/{methods → core}/facets/range/to_r.rb +0 -0
- data/lib/{methods → core}/facets/range/to_range.rb +0 -0
- data/lib/{methods → core}/facets/range/umbrella.rb +0 -0
- data/lib/{methods → core}/facets/range/within.rb +0 -0
- data/lib/{methods → core}/facets/regexp/to_re.rb +0 -0
- data/lib/{methods → core}/facets/regexp/to_regexp.rb +0 -0
- data/lib/core/facets/string.rb +1 -1
- data/lib/{methods → core}/facets/string/_crypt.rb +0 -0
- data/lib/{methods → core}/facets/string/align_center.rb +0 -0
- data/lib/{methods → core}/facets/string/align_left.rb +0 -0
- data/lib/{methods → core}/facets/string/align_right.rb +0 -0
- data/lib/{methods → core}/facets/string/at.rb +0 -0
- data/lib/{methods → core}/facets/string/brief.rb +0 -0
- data/lib/{methods → core}/facets/string/bytes.rb +0 -0
- data/lib/{methods → core}/facets/string/camelcase.rb +0 -0
- data/lib/{methods → core}/facets/string/capitalized.rb +0 -0
- data/lib/{methods → core}/facets/string/chars.rb +0 -0
- data/lib/{methods → core}/facets/string/cleave.rb +0 -0
- data/lib/{methods → core}/facets/string/cmp.rb +0 -0
- data/lib/{methods → core}/facets/string/dequote.rb +0 -0
- data/lib/{methods → core}/facets/string/divide.rb +0 -0
- data/lib/{methods → core}/facets/string/downcase.rb +0 -0
- data/lib/{methods → core}/facets/string/each_char.rb +0 -0
- data/lib/{methods → core}/facets/string/each_character.rb +0 -0
- data/lib/{methods → core}/facets/string/each_word.rb +0 -0
- data/lib/{methods → core}/facets/string/ends_with.rb +0 -0
- data/lib/{methods → core}/facets/string/expand_tabs.rb +0 -0
- data/lib/{methods → core}/facets/string/first.rb +0 -0
- data/lib/{methods → core}/facets/string/fold.rb +0 -0
- data/lib/core/facets/string/format.rb +1 -179
- data/lib/{methods → core}/facets/string/indent.rb +0 -0
- data/lib/{methods → core}/facets/string/index_all.rb +0 -0
- data/lib/{methods → core}/facets/string/last.rb +0 -0
- data/lib/{methods → core}/facets/string/lchomp.rb +0 -0
- data/lib/{methods → core}/facets/string/line_wrap.rb +0 -0
- data/lib/{methods → core}/facets/string/lines.rb +0 -0
- data/lib/{methods → core}/facets/string/lowercase.rb +0 -0
- data/lib/{methods → core}/facets/string/margin.rb +0 -0
- data/lib/{methods → core}/facets/string/mscan.rb +0 -0
- data/lib/{methods → core}/facets/string/op_minus.rb +0 -0
- data/lib/{methods → core}/facets/string/outdent.rb +0 -0
- data/lib/{methods → core}/facets/string/peek.rb +0 -0
- data/lib/{methods → core}/facets/string/poke.rb +0 -0
- data/lib/{methods → core}/facets/string/pop.rb +0 -0
- data/lib/{methods → core}/facets/string/pull.rb +0 -0
- data/lib/{methods → core}/facets/string/push.rb +0 -0
- data/lib/{methods → core}/facets/string/quote.rb +0 -0
- data/lib/{methods → core}/facets/string/range_all.rb +0 -0
- data/lib/{methods → core}/facets/string/range_of_line.rb +0 -0
- data/lib/{methods → core}/facets/string/rewrite.rb +0 -0
- data/lib/{methods → core}/facets/string/shatter.rb +0 -0
- data/lib/{methods → core}/facets/string/shift.rb +0 -0
- data/lib/{methods → core}/facets/string/snakecase.rb +0 -0
- data/lib/{methods → core}/facets/string/sprintf.rb +0 -0
- data/lib/{methods → core}/facets/string/starts_with.rb +0 -0
- data/lib/{methods → core}/facets/string/store.rb +0 -0
- data/lib/{methods → core}/facets/string/succ.rb +0 -0
- data/lib/{methods → core}/facets/string/tab.rb +0 -0
- data/lib/{methods → core}/facets/string/taballto.rb +0 -0
- data/lib/{methods → core}/facets/string/tabto.rb +0 -0
- data/lib/{methods → core}/facets/string/titlecase.rb +0 -0
- data/lib/{methods → core}/facets/string/to_b.rb +0 -0
- data/lib/{methods → core}/facets/string/to_const.rb +0 -0
- data/lib/{methods → core}/facets/string/to_date.rb +0 -0
- data/lib/{methods → core}/facets/string/to_proc.rb +0 -0
- data/lib/{methods → core}/facets/string/to_re.rb +0 -0
- data/lib/{methods → core}/facets/string/to_rx.rb +0 -0
- data/lib/{methods → core}/facets/string/to_time.rb +0 -0
- data/lib/{methods → core}/facets/string/unbracket.rb +0 -0
- data/lib/{methods → core}/facets/string/unshift.rb +0 -0
- data/lib/{methods → core}/facets/string/upcase.rb +0 -0
- data/lib/{methods → core}/facets/string/uppercase.rb +0 -0
- data/lib/{methods → core}/facets/string/whitespace.rb +0 -0
- data/lib/{methods → core}/facets/string/word_filter.rb +0 -0
- data/lib/{methods → core}/facets/string/word_wrap.rb +0 -0
- data/lib/{methods → core}/facets/string/words.rb +0 -0
- data/lib/core/facets/string/wrap.rb +189 -0
- data/lib/core/facets/symbol.rb +3 -3
- data/lib/{methods → core}/facets/symbol/lchomp.rb +0 -0
- data/lib/{methods → core}/facets/symbol/op_tilde.rb +0 -0
- data/lib/{methods → core}/facets/symbol/pad.rb +0 -0
- data/lib/{methods → core}/facets/symbol/to_const.rb +0 -0
- data/lib/{methods → core}/facets/time/to_date.rb +0 -0
- data/lib/{methods → core}/facets/time/to_s.rb +0 -0
- data/lib/{methods → core}/facets/time/to_time.rb +0 -0
- data/lib/{core/facets/hash/keyize.rb → more/facets/hash_keyize.rb} +0 -0
- data/lib/more/facets/random.rb +1 -1
- data/meta/MANIFEST +419 -470
- data/meta/facets.roll +4 -0
- data/meta/project.yaml +0 -3
- data/task/stamp +33 -0
- data/task/test/{loadtest → load} +0 -0
- data/task/test/{isotest → solo} +0 -0
- data/task/test/{general → whole} +0 -0
- data/test/unit/binding/test_self.rb +1 -1
- data/test/unit/class/test_descendents.rb +0 -6
- data/test/unit/class/test_remove_descendents.rb +19 -0
- data/test/unit/dir/test_parent.rb +14 -0
- data/test/unit/dir/test_recurse.rb +32 -0
- data/test/unit/dir/test_traverse.rb +4 -30
- data/test/unit/file/test_null.rb +12 -0
- data/test/unit/file/{test_topath.rb → test_sanitize.rb} +3 -8
- data/test/unit/file/test_split_all.rb +32 -0
- data/test/unit/hash/test_alias.rb +18 -0
- data/test/unit/hash/test_autonew.rb +13 -0
- data/test/unit/hash/test_collate.rb +31 -0
- data/test/unit/hash/{test_iterate.rb → test_each_with_key.rb} +1 -8
- data/test/unit/hash/test_has_keys.rb +0 -2
- data/test/unit/hash/test_rekey.rb +0 -21
- data/test/unit/hash/{test_merge.rb → test_reverse_merge.rb} +1 -1
- data/test/unit/hash/test_swap.rb +21 -0
- data/test/unit/hash/{test_new.rb → test_zipnew.rb} +1 -1
- data/test/unit/integer/{test_multiples.rb → test_multiple.rb} +1 -1
- data/test/unit/matchdata/test_match.rb +14 -0
- data/test/unit/matchdata/test_matchset.rb +1 -6
- data/test/unit/string/{test_format.rb → test_wrap.rb} +1 -1
- data/test/unit/{hash/test_keyize.rb → test_keyize.rb} +1 -1
- data/test/unit/test_random.rb +3 -15
- metadata +439 -481
- data/lib/core/facets/file/topath.rb +0 -65
- data/lib/core/facets/hash/iterate.rb +0 -28
- data/lib/methods/facets/binding/__DIR__.rb +0 -1
- data/lib/methods/facets/binding/__FILE__.rb +0 -1
- data/lib/methods/facets/binding/__LINE__.rb +0 -1
- data/lib/methods/facets/binding/call_stack.rb +0 -1
- data/lib/methods/facets/binding/called.rb +0 -1
- data/lib/methods/facets/binding/caller.rb +0 -1
- data/lib/methods/facets/binding/defined.rb +0 -1
- data/lib/methods/facets/binding/methodname.rb +0 -1
- data/lib/methods/facets/binding/self.rb +0 -1
- data/lib/methods/facets/class/remove_descendents.rb +0 -1
- data/lib/methods/facets/class/remove_subclasses.rb +0 -1
- data/lib/methods/facets/dir/ls_r.rb +0 -1
- data/lib/methods/facets/dir/multiglob_with_default.rb +0 -1
- data/lib/methods/facets/dir/parent.rb +0 -1
- data/lib/methods/facets/dir/recurse.rb +0 -1
- data/lib/methods/facets/enumerable/collate.rb +0 -1
- data/lib/methods/facets/enumerable/combos.rb +0 -1
- data/lib/methods/facets/facets/require_core.rb +0 -1
- data/lib/methods/facets/file/append.rb +0 -1
- data/lib/methods/facets/file/create.rb +0 -1
- data/lib/methods/facets/file/null.rb +0 -1
- data/lib/methods/facets/file/rewrite.rb +0 -1
- data/lib/methods/facets/file/rootname.rb +0 -1
- data/lib/methods/facets/file/sanitize.rb +0 -1
- data/lib/methods/facets/file/split_all.rb +0 -1
- data/lib/methods/facets/file/writelines.rb +0 -1
- data/lib/methods/facets/filetest/root.rb +0 -1
- data/lib/methods/facets/hash/alias.rb +0 -1
- data/lib/methods/facets/hash/autonew.rb +0 -1
- data/lib/methods/facets/hash/collate.rb +0 -1
- data/lib/methods/facets/hash/diff.rb +0 -1
- data/lib/methods/facets/hash/each_with_index.rb +0 -1
- data/lib/methods/facets/hash/each_with_key.rb +0 -1
- data/lib/methods/facets/hash/except.rb +0 -1
- data/lib/methods/facets/hash/join.rb +0 -1
- data/lib/methods/facets/hash/keys_to_s.rb +0 -1
- data/lib/methods/facets/hash/keys_to_sym.rb +0 -1
- data/lib/methods/facets/hash/normalize_keys.rb +0 -1
- data/lib/methods/facets/hash/op_div.rb +0 -1
- data/lib/methods/facets/hash/pairs_at.rb +0 -1
- data/lib/methods/facets/hash/reverse_merge.rb +0 -1
- data/lib/methods/facets/hash/reverse_update.rb +0 -1
- data/lib/methods/facets/hash/stringify_keys.rb +0 -1
- data/lib/methods/facets/hash/swap.rb +0 -1
- data/lib/methods/facets/hash/swapkey.rb +0 -1
- data/lib/methods/facets/hash/symbolize_keys.rb +0 -1
- data/lib/methods/facets/hash/variablize_keys.rb +0 -1
- data/lib/methods/facets/hash/zipnew.rb +0 -1
- data/lib/methods/facets/integer/bit_set.rb +0 -1
- data/lib/methods/facets/integer/clear_bitmask.rb +0 -1
- data/lib/methods/facets/integer/even.rb +0 -1
- data/lib/methods/facets/integer/fact.rb +0 -1
- data/lib/methods/facets/integer/multiple.rb +0 -1
- data/lib/methods/facets/integer/odd.rb +0 -1
- data/lib/methods/facets/integer/set_bit.rb +0 -1
- data/lib/methods/facets/integer/set_bitmask.rb +0 -1
- data/lib/methods/facets/integer/test_bit.rb +0 -1
- data/lib/methods/facets/integer/test_bitmask.rb +0 -1
- data/lib/methods/facets/io/writelines.rb +0 -1
- data/lib/methods/facets/kernel/here.rb +0 -1
- data/lib/methods/facets/kernel/returning.rb +0 -1
- data/lib/methods/facets/matchdata/match.rb +0 -1
- data/lib/methods/facets/numeric/round_at.rb +0 -1
- data/lib/methods/facets/numeric/round_to.rb +0 -1
- data/lib/methods/facets/object/to_bool.rb +0 -1
- data/lib/methods/facets/proc/update.rb +0 -1
- data/lib/methods/facets/string/format.rb +0 -1
- data/lib/methods/facets/symbol/to_proc.rb +0 -1
- data/lib/methods/facets/time/stamp.rb +0 -1
- data/lib/methods/facets/trueclass/to_bool.rb +0 -1
- data/meta/ROLLRC +0 -5
- data/task/groups +0 -24
- data/task/methods +0 -129
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,179 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Returns short abstract of long strings (first 'count'
|
4
|
-
# characters, chopped at the nearest word, appended by '...')
|
5
|
-
# force_cutoff: break forcibly at 'count' chars. Does not accept
|
6
|
-
# count < 2
|
7
|
-
#
|
8
|
-
# CREDIT: George Moschovitis
|
9
|
-
|
10
|
-
def brief(count = 128, force_cutoff = false, ellipsis="...")
|
11
|
-
return nil if count < 2
|
12
|
-
|
13
|
-
if size > count
|
14
|
-
cut_at = force_cutoff ? count : (index(' ', count-1) || count)
|
15
|
-
xstring = slice(0, cut_at)
|
16
|
-
return xstring.chomp(" ") + ellipsis
|
17
|
-
else
|
18
|
-
return self
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Cleave a string. Break a string in two parts at
|
23
|
-
# the nearest whitespace.
|
24
|
-
#
|
25
|
-
# CREDIT: Trans
|
26
|
-
|
27
|
-
def cleave(threshold=nil, len=nil)
|
28
|
-
l = (len || size / 2)
|
29
|
-
t = threshold || size
|
30
|
-
|
31
|
-
h1 = self[0...l]
|
32
|
-
h2 = self[l..-1]
|
33
|
-
|
34
|
-
i1 = h1.rindex(/\s/) || 0
|
35
|
-
d1 = (i1 - l).abs
|
36
|
-
|
37
|
-
d2 = h2.index(/\s/) || l
|
38
|
-
i2 = d2 + l
|
39
|
-
|
40
|
-
d1 = (i1-l).abs
|
41
|
-
d2 = (i2-l).abs
|
42
|
-
|
43
|
-
if [d1, d2].min > t
|
44
|
-
i = t
|
45
|
-
elsif d1 < d2
|
46
|
-
i = i1
|
47
|
-
else
|
48
|
-
i = i2
|
49
|
-
end
|
50
|
-
|
51
|
-
#dup.insert(l, "\n").gsub(/^\s+|\s+$/, '')
|
52
|
-
return self[0..i].to_s.strip, self[i+1..-1].to_s.strip
|
53
|
-
end
|
54
|
-
|
55
|
-
# Returns a new string with all new lines removed from
|
56
|
-
# adjacent lines of text.
|
57
|
-
#
|
58
|
-
# s = "This is\na test.\n\nIt clumps\nlines of text."
|
59
|
-
# s.fold
|
60
|
-
#
|
61
|
-
# _produces_
|
62
|
-
#
|
63
|
-
# "This is a test.\n\nIt clumps lines of text. "
|
64
|
-
#
|
65
|
-
# One arguable flaw with this, that might need a fix:
|
66
|
-
# if the given string ends in a newline, it is replaced with
|
67
|
-
# a single space.
|
68
|
-
#
|
69
|
-
# CREDIT: Trans
|
70
|
-
|
71
|
-
def fold(ignore_indented=false)
|
72
|
-
ns = ''
|
73
|
-
i = 0
|
74
|
-
br = self.scan(/(\n\s*\n|\Z)/m) do |m|
|
75
|
-
b = $~.begin(1)
|
76
|
-
e = $~.end(1)
|
77
|
-
nl = $&
|
78
|
-
tx = slice(i...b)
|
79
|
-
if ignore_indented and slice(i...b) =~ /^[ ]+/
|
80
|
-
ns << tx
|
81
|
-
else
|
82
|
-
ns << tx.gsub(/[ ]*\n+/,' ')
|
83
|
-
end
|
84
|
-
ns << nl
|
85
|
-
i = e
|
86
|
-
end
|
87
|
-
ns
|
88
|
-
end
|
89
|
-
|
90
|
-
# Line wrap at width.
|
91
|
-
#
|
92
|
-
# puts "1234567890".line_wrap(5)
|
93
|
-
#
|
94
|
-
# _produces_
|
95
|
-
#
|
96
|
-
# 12345
|
97
|
-
# 67890
|
98
|
-
#
|
99
|
-
# CREDIT: Trans
|
100
|
-
|
101
|
-
def line_wrap(width, tabs=4)
|
102
|
-
s = gsub(/\t/,' ' * tabs) # tabs default to 4 spaces
|
103
|
-
s = s.gsub(/\n/,' ')
|
104
|
-
r = s.scan( /.{1,#{width}}/ )
|
105
|
-
r.join("\n") << "\n"
|
106
|
-
end
|
107
|
-
|
108
|
-
# TODO: This is alternateive from glue: worth providing?
|
109
|
-
#
|
110
|
-
# Enforces a maximum width of a string inside an
|
111
|
-
# html container. If the string exceeds this maximum width
|
112
|
-
# the string gets wraped.
|
113
|
-
#
|
114
|
-
# Not really useful, better use the CSS overflow: hidden
|
115
|
-
# functionality.
|
116
|
-
#
|
117
|
-
# === Input:
|
118
|
-
# the string to be wrapped
|
119
|
-
# the enforced width
|
120
|
-
# the separator used for wrapping
|
121
|
-
#
|
122
|
-
# === Output:
|
123
|
-
# the wrapped string
|
124
|
-
#
|
125
|
-
# === Example:
|
126
|
-
# text = "1111111111111111111111111111111111111111111"
|
127
|
-
# text = wrap(text, 10, " ")
|
128
|
-
# p text # => "1111111111 1111111111 1111111111"
|
129
|
-
#
|
130
|
-
# See the test cases to better understand the behaviour!
|
131
|
-
|
132
|
-
# def wrap(width = 20, separator = " ")
|
133
|
-
# re = /([^#{separator}]{1,#{width}})/
|
134
|
-
# scan(re).join(separator)
|
135
|
-
# end
|
136
|
-
|
137
|
-
# Word wrap a string not exceeding max width.
|
138
|
-
#
|
139
|
-
# puts "this is a test".word_wrap(4)
|
140
|
-
#
|
141
|
-
# _produces_
|
142
|
-
#
|
143
|
-
# this
|
144
|
-
# is a
|
145
|
-
# test
|
146
|
-
#
|
147
|
-
# CREDIT: Gavin Kistner
|
148
|
-
# CREDIT: Dayne Broderson
|
149
|
-
|
150
|
-
def word_wrap( col_width=80 )
|
151
|
-
self.dup.word_wrap!( col_width )
|
152
|
-
end
|
153
|
-
|
154
|
-
# As with #word_wrap, but modifies the string in place.
|
155
|
-
#
|
156
|
-
# CREDIT: Gavin Kistner
|
157
|
-
# CREDIT: Dayne Broderson
|
158
|
-
|
159
|
-
def word_wrap!( col_width=80 )
|
160
|
-
self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
|
161
|
-
self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
|
162
|
-
self
|
163
|
-
end
|
164
|
-
|
165
|
-
# old def
|
166
|
-
|
167
|
-
#def word_wrap(max=80)
|
168
|
-
# c = dup
|
169
|
-
# c.word_wrap!(max)
|
170
|
-
# c
|
171
|
-
#end
|
172
|
-
|
173
|
-
#def word_wrap!(max=80)
|
174
|
-
# raise ArgumentError, "Wrap margin too low: #{n}" if max <= 2
|
175
|
-
# #gsub!( Regexp.new( "(.{1,#{max-1}}\\w)\\b\\s*" ), "\\1\n")
|
176
|
-
# gsub!( /(.{1,#{max-1}}\S)([ ]|\n)/, "\\1\n")
|
177
|
-
#end
|
178
|
-
|
179
|
-
end
|
1
|
+
require 'facets/string/interpolate.rb'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,189 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
# Returns short abstract of long strings; not exceeding +range+
|
4
|
+
# characters. If range is an integer then the minimum is 20%
|
5
|
+
# of the maximum. The string is chopped at the nearest word
|
6
|
+
# if possible, and appended by +ellipsis+, which defaults
|
7
|
+
# to '...'.
|
8
|
+
#
|
9
|
+
# CREDIT: George Moschovitis
|
10
|
+
# CREDIT: Trans
|
11
|
+
|
12
|
+
def brief(range=76, ellipsis="...")
|
13
|
+
if Range===range
|
14
|
+
min = range.first
|
15
|
+
max = range.last
|
16
|
+
else
|
17
|
+
max = range
|
18
|
+
min = max - (max/5).to_i
|
19
|
+
range = min..max
|
20
|
+
end
|
21
|
+
|
22
|
+
if size > max
|
23
|
+
cut_at = rindex(/\b/, max) || max
|
24
|
+
cut_at = max if cut_at < min
|
25
|
+
xstring = slice(0, cut_at)
|
26
|
+
xstring.chomp(" ") + ellipsis
|
27
|
+
else
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Cleave a string. Break a string in two parts at
|
33
|
+
# the nearest whitespace.
|
34
|
+
#
|
35
|
+
# CREDIT: Trans
|
36
|
+
|
37
|
+
def cleave(threshold=nil, len=nil)
|
38
|
+
l = (len || size / 2)
|
39
|
+
t = threshold || size
|
40
|
+
|
41
|
+
h1 = self[0...l]
|
42
|
+
h2 = self[l..-1]
|
43
|
+
|
44
|
+
i1 = h1.rindex(/\s/) || 0
|
45
|
+
d1 = (i1 - l).abs
|
46
|
+
|
47
|
+
d2 = h2.index(/\s/) || l
|
48
|
+
i2 = d2 + l
|
49
|
+
|
50
|
+
d1 = (i1-l).abs
|
51
|
+
d2 = (i2-l).abs
|
52
|
+
|
53
|
+
if [d1, d2].min > t
|
54
|
+
i = t
|
55
|
+
elsif d1 < d2
|
56
|
+
i = i1
|
57
|
+
else
|
58
|
+
i = i2
|
59
|
+
end
|
60
|
+
|
61
|
+
#dup.insert(l, "\n").gsub(/^\s+|\s+$/, '')
|
62
|
+
return self[0..i].to_s.strip, self[i+1..-1].to_s.strip
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns a new string with all new lines removed from
|
66
|
+
# adjacent lines of text.
|
67
|
+
#
|
68
|
+
# s = "This is\na test.\n\nIt clumps\nlines of text."
|
69
|
+
# s.fold
|
70
|
+
#
|
71
|
+
# _produces_
|
72
|
+
#
|
73
|
+
# "This is a test.\n\nIt clumps lines of text. "
|
74
|
+
#
|
75
|
+
# One arguable flaw with this, that might need a fix:
|
76
|
+
# if the given string ends in a newline, it is replaced with
|
77
|
+
# a single space.
|
78
|
+
#
|
79
|
+
# CREDIT: Trans
|
80
|
+
|
81
|
+
def fold(ignore_indented=false)
|
82
|
+
ns = ''
|
83
|
+
i = 0
|
84
|
+
br = self.scan(/(\n\s*\n|\Z)/m) do |m|
|
85
|
+
b = $~.begin(1)
|
86
|
+
e = $~.end(1)
|
87
|
+
nl = $&
|
88
|
+
tx = slice(i...b)
|
89
|
+
if ignore_indented and slice(i...b) =~ /^[ ]+/
|
90
|
+
ns << tx
|
91
|
+
else
|
92
|
+
ns << tx.gsub(/[ ]*\n+/,' ')
|
93
|
+
end
|
94
|
+
ns << nl
|
95
|
+
i = e
|
96
|
+
end
|
97
|
+
ns
|
98
|
+
end
|
99
|
+
|
100
|
+
# Line wrap at width.
|
101
|
+
#
|
102
|
+
# puts "1234567890".line_wrap(5)
|
103
|
+
#
|
104
|
+
# _produces_
|
105
|
+
#
|
106
|
+
# 12345
|
107
|
+
# 67890
|
108
|
+
#
|
109
|
+
# CREDIT: Trans
|
110
|
+
|
111
|
+
def line_wrap(width, tabs=4)
|
112
|
+
s = gsub(/\t/,' ' * tabs) # tabs default to 4 spaces
|
113
|
+
s = s.gsub(/\n/,' ')
|
114
|
+
r = s.scan( /.{1,#{width}}/ )
|
115
|
+
r.join("\n") << "\n"
|
116
|
+
end
|
117
|
+
|
118
|
+
# TODO: This is alternateive from glue: worth providing?
|
119
|
+
#
|
120
|
+
# Enforces a maximum width of a string inside an
|
121
|
+
# html container. If the string exceeds this maximum width
|
122
|
+
# the string gets wraped.
|
123
|
+
#
|
124
|
+
# Not really useful, better use the CSS overflow: hidden
|
125
|
+
# functionality.
|
126
|
+
#
|
127
|
+
# === Input:
|
128
|
+
# the string to be wrapped
|
129
|
+
# the enforced width
|
130
|
+
# the separator used for wrapping
|
131
|
+
#
|
132
|
+
# === Output:
|
133
|
+
# the wrapped string
|
134
|
+
#
|
135
|
+
# === Example:
|
136
|
+
# text = "1111111111111111111111111111111111111111111"
|
137
|
+
# text = wrap(text, 10, " ")
|
138
|
+
# p text # => "1111111111 1111111111 1111111111"
|
139
|
+
#
|
140
|
+
# See the test cases to better understand the behaviour!
|
141
|
+
|
142
|
+
# def wrap(width = 20, separator = " ")
|
143
|
+
# re = /([^#{separator}]{1,#{width}})/
|
144
|
+
# scan(re).join(separator)
|
145
|
+
# end
|
146
|
+
|
147
|
+
# Word wrap a string not exceeding max width.
|
148
|
+
#
|
149
|
+
# puts "this is a test".word_wrap(4)
|
150
|
+
#
|
151
|
+
# _produces_
|
152
|
+
#
|
153
|
+
# this
|
154
|
+
# is a
|
155
|
+
# test
|
156
|
+
#
|
157
|
+
# CREDIT: Gavin Kistner
|
158
|
+
# CREDIT: Dayne Broderson
|
159
|
+
|
160
|
+
def word_wrap( col_width=80 )
|
161
|
+
self.dup.word_wrap!( col_width )
|
162
|
+
end
|
163
|
+
|
164
|
+
# As with #word_wrap, but modifies the string in place.
|
165
|
+
#
|
166
|
+
# CREDIT: Gavin Kistner
|
167
|
+
# CREDIT: Dayne Broderson
|
168
|
+
|
169
|
+
def word_wrap!( col_width=80 )
|
170
|
+
self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
|
171
|
+
self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
|
172
|
+
self
|
173
|
+
end
|
174
|
+
|
175
|
+
# old def
|
176
|
+
|
177
|
+
#def word_wrap(max=80)
|
178
|
+
# c = dup
|
179
|
+
# c.word_wrap!(max)
|
180
|
+
# c
|
181
|
+
#end
|
182
|
+
|
183
|
+
#def word_wrap!(max=80)
|
184
|
+
# raise ArgumentError, "Wrap margin too low: #{n}" if max <= 2
|
185
|
+
# #gsub!( Regexp.new( "(.{1,#{max-1}}\\w)\\b\\s*" ), "\\1\n")
|
186
|
+
# gsub!( /(.{1,#{max-1}}\S)([ ]|\n)/, "\\1\n")
|
187
|
+
#end
|
188
|
+
|
189
|
+
end
|