facets 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ProjectInfo +32 -25
- data/data/facets/index.yml +30 -6
- data/data/facets/units/binary/base.yaml +12 -0
- data/data/facets/units/binary/extra.yaml +8 -0
- data/data/facets/units/cex.yaml +7 -0
- data/data/facets/units/currency/base.yaml +268 -0
- data/data/facets/units/default.yaml +22 -0
- data/data/facets/units/dump_yaml.rb +309 -0
- data/data/facets/units/si/base.yaml +36 -0
- data/data/facets/units/si/derived.yaml +133 -0
- data/data/facets/units/si/extra.yaml +107 -0
- data/data/facets/units/standard.yaml +5 -0
- data/data/facets/units/uk.yaml +16 -0
- data/data/facets/units/uk/base.yaml +107 -0
- data/data/facets/units/us.yaml +16 -0
- data/data/facets/units/us/base.yaml +112 -0
- data/data/facets/units/xmethods/cached.yaml +83 -0
- data/data/facets/units/xmethods/mapping.yaml +85 -0
- data/lib/facet/array/join_sentence.rb +1 -0
- data/lib/facet/class/cattr.rb +1 -0
- data/lib/facet/class/cattr_accessor.rb +1 -0
- data/lib/facet/class/cattr_reader.rb +1 -0
- data/lib/facet/class/cattr_writer.rb +1 -0
- data/lib/facet/elementor.rb +1 -0
- data/lib/facet/enumerable/accumulate.rb +1 -0
- data/lib/facet/enumerable/collect_if.rb +1 -0
- data/lib/facet/enumerable/map_if.rb +1 -0
- data/lib/facet/file/self/append.rb +1 -0
- data/lib/facet/file/self/read_binary.rb +1 -0
- data/lib/facet/file/self/write.rb +1 -0
- data/lib/facet/json.rb +1 -0
- data/lib/facet/kernel/__self__.rb +1 -0
- data/lib/facet/kernel/methodname.rb +1 -0
- data/lib/facet/module/attr_query.rb +1 -0
- data/lib/facet/module/attr_validator.rb +1 -0
- data/lib/facet/module/inherit.rb +1 -0
- data/lib/facet/module/let.rb +1 -0
- data/lib/facet/module/mattr.rb +1 -0
- data/lib/facet/module/mattr_accessor.rb +1 -0
- data/lib/facet/module/mattr_reader.rb +1 -0
- data/lib/facet/module/mattr_writer.rb +1 -0
- data/lib/facet/module/singleton_to_module.rb +1 -0
- data/lib/facet/nilclass/op_cmp.rb +1 -0
- data/lib/facet/nilclass/succ.rb +1 -0
- data/lib/facet/recorder.rb +1 -0
- data/lib/facet/xoxo.rb +1 -0
- data/lib/facets/core/array.rb +1 -0
- data/lib/facets/core/array/join_sentence.rb +12 -0
- data/lib/facets/core/class.rb +4 -0
- data/lib/facets/core/{module → class}/cattr.rb +7 -9
- data/lib/facets/core/class/cattr_accessor.rb +2 -0
- data/lib/facets/core/class/cattr_reader.rb +3 -0
- data/lib/facets/core/class/cattr_writer.rb +2 -0
- data/lib/facets/core/dir/self/ls_r.rb +4 -9
- data/lib/facets/core/enumerable.rb +3 -0
- data/lib/facets/core/enumerable/accumulate.rb +25 -0
- data/lib/facets/core/enumerable/collect_if.rb +15 -0
- data/lib/facets/core/enumerable/ew.rb +1 -5
- data/lib/facets/core/enumerable/map_if.rb +3 -0
- data/lib/facets/core/file.rb +3 -0
- data/lib/facets/core/file/self/append.rb +8 -0
- data/lib/facets/core/file/self/create.rb +14 -8
- data/lib/facets/core/file/self/open_as_string.rb +31 -13
- data/lib/facets/core/file/self/read_binary.rb +8 -0
- data/lib/facets/core/file/self/read_list.rb +11 -7
- data/lib/facets/core/file/self/write.rb +8 -0
- data/lib/facets/core/fileutils/wc.rb +4 -9
- data/lib/facets/core/fileutils/which.rb +4 -9
- data/lib/facets/core/kernel.rb +2 -1
- data/lib/facets/core/kernel/__self__.rb +32 -0
- data/lib/facets/core/kernel/as.rb +1 -1
- data/lib/facets/core/kernel/assign_from.rb +3 -3
- data/lib/facets/core/kernel/assign_with.rb +2 -0
- data/lib/facets/core/kernel/me.rb +3 -2
- data/lib/facets/core/kernel/method_name.rb +2 -49
- data/lib/facets/core/kernel/methodname.rb +49 -0
- data/lib/facets/core/module.rb +9 -4
- data/lib/facets/core/module/attr_query.rb +56 -0
- data/lib/facets/core/module/attr_validator.rb +18 -0
- data/lib/facets/core/module/inherit.rb +70 -0
- data/lib/facets/core/module/integrate.rb +1 -1
- data/lib/facets/core/module/let.rb +55 -0
- data/lib/facets/core/module/mattr.rb +180 -0
- data/lib/facets/core/module/{cattr_accessor.rb → mattr_accessor.rb} +0 -0
- data/lib/facets/core/module/{cattr_reader.rb → mattr_reader.rb} +0 -0
- data/lib/facets/core/module/{cattr_writer.rb → mattr_writer.rb} +0 -0
- data/lib/facets/core/module/on_included.rb +3 -1
- data/lib/facets/core/module/singleton_to_module.rb +23 -0
- data/lib/facets/core/nilclass.rb +2 -0
- data/lib/facets/core/string/methodize.rb +4 -3
- data/lib/facets/core/string/modulize.rb +3 -3
- data/lib/facets/more/ansicode.rb +1 -1
- data/lib/facets/more/aspects.rb +1 -1
- data/lib/facets/more/basicobject.rb +67 -22
- data/lib/facets/more/classinherit.rb +2 -2
- data/lib/facets/more/cloneable.rb +1 -1
- data/lib/facets/more/consoleapp.rb +31 -20
- data/lib/facets/more/dictionary.rb +1 -1
- data/lib/facets/more/filelist.rb +2 -10
- data/lib/facets/more/functor.rb +6 -6
- data/lib/facets/more/json.rb +891 -0
- data/lib/facets/more/methodprobe.rb +1 -1
- data/lib/facets/more/multiton.rb +16 -8
- data/lib/facets/more/nilcomparable.rb +31 -49
- data/lib/facets/more/openobject.rb +50 -10
- data/lib/facets/more/recorder.rb +125 -0
- data/lib/facets/more/rtals.rb +199 -4
- data/lib/facets/more/typecast.rb +12 -12
- data/lib/facets/more/units.rb +20 -14
- data/lib/facets/more/xoxo.rb +519 -0
- data/setup.rb +283 -271
- data/test/lib/facets/core/array/test_at_rand.rb +1 -1
- data/test/lib/facets/core/array/test_delete_unless.rb +1 -1
- data/test/lib/facets/core/array/test_delete_values.rb +1 -1
- data/test/lib/facets/core/array/test_delete_values_at.rb +1 -1
- data/test/lib/facets/core/array/test_first.rb +1 -1
- data/test/lib/facets/core/array/test_head.rb +1 -1
- data/test/lib/facets/core/array/test_last_index.rb +1 -1
- data/test/lib/facets/core/array/test_merge.rb +1 -1
- data/test/lib/facets/core/array/test_mid.rb +1 -1
- data/test/lib/facets/core/array/test_middle.rb +1 -1
- data/test/lib/facets/core/array/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/array/test_op_store.rb +1 -1
- data/test/lib/facets/core/array/test_pick.rb +1 -1
- data/test/lib/facets/core/array/test_pos.rb +1 -1
- data/test/lib/facets/core/array/test_pull.rb +1 -1
- data/test/lib/facets/core/array/test_rand_index.rb +1 -1
- data/test/lib/facets/core/array/test_rand_subset.rb +1 -1
- data/test/lib/facets/core/array/test_range.rb +1 -1
- data/test/lib/facets/core/array/test_rotate.rb +1 -1
- data/test/lib/facets/core/array/test_select.rb +1 -1
- data/test/lib/facets/core/array/test_shuffle.rb +1 -1
- data/test/lib/facets/core/array/test_slap.rb +1 -1
- data/test/lib/facets/core/array/test_thru.rb +1 -1
- data/test/lib/facets/core/array/test_to_b.rb +1 -1
- data/test/lib/facets/core/array/test_to_h.rb +1 -1
- data/test/lib/facets/core/array/test_to_hash.rb +1 -1
- data/test/lib/facets/core/binding/self/test_of_caller.rb +1 -1
- data/test/lib/facets/core/binding/test___LINE__.rb +1 -1
- data/test/lib/facets/core/binding/test_call_stack.rb +1 -1
- data/test/lib/facets/core/binding/test_called.rb +1 -1
- data/test/lib/facets/core/binding/test_caller.rb +1 -1
- data/test/lib/facets/core/binding/test_defined.rb +1 -1
- data/test/lib/facets/core/binding/test_eval.rb +1 -1
- data/test/lib/facets/core/binding/test_local_variables.rb +1 -1
- data/test/lib/facets/core/binding/test_method_name.rb +1 -1
- data/test/lib/facets/core/binding/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/binding/test_op_store.rb +1 -1
- data/test/lib/facets/core/binding/test_self.rb +1 -1
- data/test/lib/facets/core/{module/test_cattr_accessor.rb → class/test_cattr.rb} +11 -3
- data/test/lib/facets/core/class/test_descendents.rb +1 -1
- data/test/lib/facets/core/class/test_method_name.rb +1 -1
- data/test/lib/facets/core/class/test_remove_descendents.rb +1 -1
- data/test/lib/facets/core/class/test_unix_path.rb +1 -1
- data/test/lib/facets/core/comparable/test_at_least.rb +1 -1
- data/test/lib/facets/core/comparable/test_clip.rb +1 -1
- data/test/lib/facets/core/comparable/test_cmp.rb +1 -1
- data/test/lib/facets/core/continuation/self/test_create.rb +1 -1
- data/test/lib/facets/core/date/test_days_in_month.rb +1 -1
- data/test/lib/facets/core/date/test_days_of_month.rb +1 -1
- data/test/lib/facets/core/date/test_stamp.rb +1 -1
- data/test/lib/facets/core/date/test_to_date.rb +1 -1
- data/test/lib/facets/core/date/test_to_s.rb +1 -1
- data/test/lib/facets/core/date/test_to_time.rb +1 -1
- data/test/lib/facets/core/dir/self/test_ancestor.rb +1 -1
- data/test/lib/facets/core/dir/self/test_ascend.rb +1 -1
- data/test/lib/facets/core/enumerable/self/test_combinations.rb +1 -1
- data/test/lib/facets/core/enumerable/self/test_cross.rb +1 -1
- data/test/lib/facets/core/enumerable/test_collect_with_index.rb +1 -1
- data/test/lib/facets/core/enumerable/test_commonality.rb +1 -1
- data/test/lib/facets/core/enumerable/test_compact_collect.rb +1 -1
- data/test/lib/facets/core/enumerable/test_cross.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_combination.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_pair.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_slice.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_unique_pair.rb +1 -1
- data/test/lib/facets/core/enumerable/test_entropy.rb +1 -1
- data/test/lib/facets/core/enumerable/test_every.rb +1 -1
- data/test/lib/facets/core/enumerable/test_ew.rb +1 -1
- data/test/lib/facets/core/enumerable/test_filter_collect.rb +1 -1
- data/test/lib/facets/core/enumerable/test_find_collisions.rb +1 -1
- data/test/lib/facets/core/enumerable/test_frequency.rb +1 -1
- data/test/lib/facets/core/enumerable/test_graph.rb +1 -1
- data/test/lib/facets/core/enumerable/test_ideal_entropy.rb +1 -1
- data/test/lib/facets/core/enumerable/test_none.rb +1 -1
- data/test/lib/facets/core/enumerable/test_occur.rb +1 -1
- data/test/lib/facets/core/enumerable/test_one.rb +1 -1
- data/test/lib/facets/core/enumerable/test_op_pow.rb +1 -1
- data/test/lib/facets/core/enumerable/test_partition_by.rb +1 -1
- data/test/lib/facets/core/enumerable/test_permute.rb +1 -1
- data/test/lib/facets/core/enumerable/test_probability.rb +1 -1
- data/test/lib/facets/core/enumerable/test_to_h.rb +1 -1
- data/test/lib/facets/core/enumerable/test_uniq_by.rb +1 -1
- data/test/lib/facets/core/file/self/test_create.rb +14 -9
- data/test/lib/facets/core/file/self/test_open_as_string.rb +21 -11
- data/test/lib/facets/core/file/self/test_read_list.rb +11 -8
- data/test/lib/facets/core/file/self/test_sanitize.rb +1 -1
- data/test/lib/facets/core/file/self/test_split_all.rb +1 -1
- data/test/lib/facets/core/float/test_round_at.rb +1 -1
- data/test/lib/facets/core/float/test_round_to.rb +1 -1
- data/test/lib/facets/core/hash/self/test_zipnew.rb +1 -1
- data/test/lib/facets/core/hash/test_alias.rb +1 -1
- data/test/lib/facets/core/hash/test_assert_has_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_assert_has_only_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_at.rb +1 -1
- data/test/lib/facets/core/hash/test_collate.rb +1 -1
- data/test/lib/facets/core/hash/test_each.rb +1 -1
- data/test/lib/facets/core/hash/test_each_with_index.rb +1 -1
- data/test/lib/facets/core/hash/test_each_with_key.rb +1 -1
- data/test/lib/facets/core/hash/test_graph.rb +1 -1
- data/test/lib/facets/core/hash/test_has_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_has_only_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_inverse.rb +1 -1
- data/test/lib/facets/core/hash/test_keys_to_s.rb +1 -1
- data/test/lib/facets/core/hash/test_keys_to_sym.rb +1 -1
- data/test/lib/facets/core/hash/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/hash/test_op_lshift.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_key.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_pair.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_value.rb +1 -1
- data/test/lib/facets/core/hash/test_replace_each.rb +1 -1
- data/test/lib/facets/core/hash/test_shuffle.rb +1 -1
- data/test/lib/facets/core/hash/test_slice.rb +1 -1
- data/test/lib/facets/core/hash/test_swap.rb +1 -1
- data/test/lib/facets/core/hash/test_swapkey.rb +1 -1
- data/test/lib/facets/core/hash/test_to_h.rb +1 -1
- data/test/lib/facets/core/hash/test_to_ostruct.rb +1 -1
- data/test/lib/facets/core/hash/test_to_ostruct_recurse.rb +1 -1
- data/test/lib/facets/core/hash/test_traverse.rb +1 -1
- data/test/lib/facets/core/hash/test_update_each.rb +1 -1
- data/test/lib/facets/core/hash/test_update_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_update_values.rb +1 -1
- data/test/lib/facets/core/hash/test_weave.rb +1 -1
- data/test/lib/facets/core/integer/test_factorial.rb +1 -1
- data/test/lib/facets/core/integer/test_multiple.rb +1 -1
- data/test/lib/facets/core/integer/test_ordinal.rb +1 -1
- data/test/lib/facets/core/integer/test_times_collect.rb +1 -1
- data/test/lib/facets/core/kernel/test___class__.rb +1 -1
- data/test/lib/facets/core/kernel/test_as.rb +1 -1
- data/test/lib/facets/core/kernel/test_assign_from.rb +1 -1
- data/test/lib/facets/core/kernel/test_assign_with.rb +1 -1
- data/test/lib/facets/core/kernel/test_bool.rb +1 -1
- data/test/lib/facets/core/kernel/test_bug.rb +1 -1
- data/test/lib/facets/core/kernel/test_call_stack.rb +1 -1
- data/test/lib/facets/core/kernel/test_called.rb +1 -1
- data/test/lib/facets/core/kernel/test_constant.rb +1 -1
- data/test/lib/facets/core/kernel/test_copy.rb +1 -1
- data/test/lib/facets/core/kernel/test_deep_copy.rb +1 -1
- data/test/lib/facets/core/kernel/test_demo.rb +1 -1
- data/test/lib/facets/core/kernel/test_fn.rb +1 -1
- data/test/lib/facets/core/kernel/test_generate_method_name.rb +1 -1
- data/test/lib/facets/core/kernel/test_get_by_id.rb +1 -1
- data/test/lib/facets/core/kernel/test_here.rb +1 -1
- data/test/lib/facets/core/kernel/test_in.rb +1 -1
- data/test/lib/facets/core/kernel/test_maybe.rb +1 -1
- data/test/lib/facets/core/kernel/test_metaclass.rb +1 -1
- data/test/lib/facets/core/kernel/test_method.rb +1 -1
- data/test/lib/facets/core/kernel/{test_method_name.rb → test_methodname.rb} +3 -3
- data/test/lib/facets/core/kernel/test_methods.rb +1 -1
- data/test/lib/facets/core/kernel/test_new.rb +1 -1
- data/test/lib/facets/core/kernel/test_object_class.rb +1 -1
- data/test/lib/facets/core/kernel/test_object_hexid.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_all.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_esc.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_facet.rb +1 -1
- data/test/lib/facets/core/kernel/test_resc.rb +1 -1
- data/test/lib/facets/core/kernel/test_returning.rb +1 -1
- data/test/lib/facets/core/kernel/test_send_as.rb +1 -1
- data/test/lib/facets/core/kernel/test_set_from.rb +1 -1
- data/test/lib/facets/core/kernel/test_set_with.rb +1 -1
- data/test/lib/facets/core/kernel/test_silently.rb +1 -1
- data/test/lib/facets/core/kernel/test_singleton.rb +1 -1
- data/test/lib/facets/core/kernel/test_superior.rb +1 -1
- data/test/lib/facets/core/kernel/test_supermethod.rb +1 -1
- data/test/lib/facets/core/kernel/test_this.rb +1 -1
- data/test/lib/facets/core/kernel/test_to_b.rb +1 -1
- data/test/lib/facets/core/kernel/test_to_bool.rb +1 -1
- data/test/lib/facets/core/kernel/test_uri.rb +1 -1
- data/test/lib/facets/core/kernel/test_val.rb +1 -1
- data/test/lib/facets/core/kernel/test_with_accessor.rb +1 -1
- data/test/lib/facets/core/matchdata/test_match.rb +1 -1
- data/test/lib/facets/core/matchdata/test_matchtree.rb +1 -1
- data/test/lib/facets/core/module/test_abstract.rb +1 -1
- data/test/lib/facets/core/module/test_alias_module_function.rb +1 -1
- data/test/lib/facets/core/module/test_ancestor.rb +1 -1
- data/test/lib/facets/core/module/test_basename.rb +1 -1
- data/test/lib/facets/core/module/test_by_name.rb +1 -1
- data/test/lib/facets/core/module/test_clone_using.rb +1 -1
- data/test/lib/facets/core/module/test_dirname.rb +1 -1
- data/test/lib/facets/core/module/test_equate_on.rb +1 -1
- data/test/lib/facets/core/module/test_generate_instance_method_name.rb +1 -1
- data/test/lib/facets/core/module/test_include_as.rb +1 -1
- data/test/lib/facets/core/module/test_inherit.rb +58 -0
- data/test/lib/facets/core/module/test_initializer.rb +1 -1
- data/test/lib/facets/core/module/test_instance_methods.rb +1 -1
- data/test/lib/facets/core/module/test_integrate.rb +1 -1
- data/test/lib/facets/core/module/test_let.rb +31 -0
- data/test/lib/facets/core/module/test_mattr.rb +71 -0
- data/test/lib/facets/core/module/test_memoize.rb +1 -1
- data/test/lib/facets/core/module/test_modspace.rb +1 -1
- data/test/lib/facets/core/module/test_namespace.rb +1 -1
- data/test/lib/facets/core/module/test_nesting.rb +1 -1
- data/test/lib/facets/core/module/test_on_included.rb +36 -0
- data/test/lib/facets/core/module/test_redef.rb +1 -1
- data/test/lib/facets/core/module/test_redefine_method.rb +1 -1
- data/test/lib/facets/core/module/test_redirect.rb +1 -1
- data/test/lib/facets/core/module/test_redirect_method.rb +1 -1
- data/test/lib/facets/core/module/test_remove.rb +1 -1
- data/test/lib/facets/core/module/test_rename.rb +1 -1
- data/test/lib/facets/core/module/test_rename_method.rb +1 -1
- data/test/lib/facets/core/module/test_revisal.rb +1 -1
- data/test/lib/facets/core/module/test_shadow_method.rb +1 -1
- data/test/lib/facets/core/module/test_sort_on.rb +1 -1
- data/test/lib/facets/core/module/test_undef.rb +1 -1
- data/test/lib/facets/core/module/test_wrap.rb +1 -1
- data/test/lib/facets/core/module/test_wrap_method.rb +1 -1
- data/test/lib/facets/core/nilclass/{test_to_f.rb → test_blank.rb} +5 -5
- data/test/lib/facets/core/nilclass/test_empty.rb +1 -1
- data/test/lib/facets/core/nilclass/test_include.rb +1 -1
- data/test/lib/facets/core/nilclass/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/nilclass/test_size.rb +1 -1
- data/test/lib/facets/core/nilclass/test_to_h.rb +1 -1
- data/test/lib/facets/core/{float → numeric}/test_approx.rb +4 -3
- data/test/lib/facets/core/numeric/test_ceil_multiple.rb +1 -1
- data/test/lib/facets/core/numeric/test_succ.rb +1 -1
- data/test/lib/facets/core/numeric/test_to_b.rb +1 -1
- data/test/lib/facets/core/ostruct/test___merge__.rb +1 -1
- data/test/lib/facets/core/ostruct/test___update__.rb +1 -1
- data/test/lib/facets/core/ostruct/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/ostruct/test_op_store.rb +1 -1
- data/test/lib/facets/core/proc/test_compose.rb +1 -1
- data/test/lib/facets/core/proc/test_to_method.rb +1 -1
- data/test/lib/facets/core/range/test_to_r.rb +1 -1
- data/test/lib/facets/core/range/test_to_range.rb +1 -1
- data/test/lib/facets/core/range/test_umbrella.rb +1 -1
- data/test/lib/facets/core/range/test_within.rb +1 -1
- data/test/lib/facets/core/regexp/test_arity.rb +1 -1
- data/test/lib/facets/core/regexp/test_to_re.rb +1 -1
- data/test/lib/facets/core/regexp/test_to_regexp.rb +1 -1
- data/test/lib/facets/core/string/self/test_interpolate.rb +1 -1
- data/test/lib/facets/core/string/self/test_patterns.rb +1 -1
- data/test/lib/facets/core/string/self/test_rand_letter.rb +1 -1
- data/test/lib/facets/core/string/test_align_center.rb +1 -1
- data/test/lib/facets/core/string/test_at_rand.rb +1 -1
- data/test/lib/facets/core/string/test_basename.rb +1 -1
- data/test/lib/facets/core/string/test_blank.rb +1 -1
- data/test/lib/facets/core/string/test_bracket.rb +1 -1
- data/test/lib/facets/core/string/test_camelcase.rb +1 -1
- data/test/lib/facets/core/string/test_camelize.rb +1 -1
- data/test/lib/facets/core/string/test_capitalized.rb +1 -1
- data/test/lib/facets/core/string/test_chars.rb +1 -1
- data/test/lib/facets/core/string/test_cmp.rb +1 -1
- data/test/lib/facets/core/string/test_demodulize.rb +1 -1
- data/test/lib/facets/core/string/test_downcase.rb +1 -1
- data/test/lib/facets/core/string/test_dresner.rb +1 -1
- data/test/lib/facets/core/string/test_each_char.rb +1 -1
- data/test/lib/facets/core/string/test_each_word.rb +1 -1
- data/test/lib/facets/core/string/test_first.rb +1 -1
- data/test/lib/facets/core/string/test_fold.rb +1 -1
- data/test/lib/facets/core/string/test_frequency.rb +1 -1
- data/test/lib/facets/core/string/test_humanize.rb +1 -1
- data/test/lib/facets/core/string/test_indent.rb +1 -1
- data/test/lib/facets/core/string/test_index_all.rb +1 -1
- data/test/lib/facets/core/string/test_last.rb +1 -1
- data/test/lib/facets/core/string/test_line_wrap.rb +1 -1
- data/test/lib/facets/core/string/test_lines.rb +1 -1
- data/test/lib/facets/core/string/test_lowercase.rb +1 -1
- data/test/lib/facets/core/string/test_margin.rb +1 -1
- data/test/lib/facets/core/string/test_methodize.rb +1 -1
- data/test/lib/facets/core/string/test_modulize.rb +1 -1
- data/test/lib/facets/core/string/test_mscan.rb +1 -1
- data/test/lib/facets/core/string/test_natcmp.rb +1 -1
- data/test/lib/facets/core/string/test_nchar.rb +1 -1
- data/test/lib/facets/core/string/test_pathize.rb +1 -1
- data/test/lib/facets/core/string/test_pop.rb +1 -1
- data/test/lib/facets/core/string/test_probability.rb +1 -1
- data/test/lib/facets/core/string/test_push.rb +1 -1
- data/test/lib/facets/core/string/test_quote.rb +1 -1
- data/test/lib/facets/core/string/test_rand_byte.rb +1 -1
- data/test/lib/facets/core/string/test_rand_index.rb +1 -1
- data/test/lib/facets/core/string/test_range.rb +1 -1
- data/test/lib/facets/core/string/test_range_all.rb +1 -1
- data/test/lib/facets/core/string/test_range_of_line.rb +1 -1
- data/test/lib/facets/core/string/test_regesc.rb +1 -1
- data/test/lib/facets/core/string/test_shatter.rb +1 -1
- data/test/lib/facets/core/string/test_shift.rb +1 -1
- data/test/lib/facets/core/string/test_shuffle.rb +1 -1
- data/test/lib/facets/core/string/test_similarity.rb +1 -1
- data/test/lib/facets/core/string/test_singular.rb +1 -1
- data/test/lib/facets/core/string/test_slap.rb +1 -1
- data/test/lib/facets/core/string/test_soundex.rb +1 -1
- data/test/lib/facets/core/string/test_succ.rb +1 -1
- data/test/lib/facets/core/string/test_to_a.rb +1 -1
- data/test/lib/facets/core/string/test_to_arr.rb +1 -1
- data/test/lib/facets/core/string/test_to_b.rb +1 -1
- data/test/lib/facets/core/string/test_to_const.rb +1 -1
- data/test/lib/facets/core/string/test_to_date.rb +1 -1
- data/test/lib/facets/core/string/test_to_proc.rb +1 -1
- data/test/lib/facets/core/string/test_to_re.rb +1 -1
- data/test/lib/facets/core/string/test_to_time.rb +1 -1
- data/test/lib/facets/core/string/test_unix_crypt.rb +1 -1
- data/test/lib/facets/core/string/test_unpack.rb +1 -1
- data/test/lib/facets/core/string/test_unshift.rb +1 -1
- data/test/lib/facets/core/string/test_upcase.rb +1 -1
- data/test/lib/facets/core/string/test_whitespace.rb +1 -1
- data/test/lib/facets/core/string/test_word_filter.rb +1 -1
- data/test/lib/facets/core/string/test_word_wrap.rb +1 -1
- data/test/lib/facets/core/string/test_words.rb +1 -1
- data/test/lib/facets/core/symbol/test_camelcase.rb +1 -1
- data/test/lib/facets/core/symbol/test_camelize.rb +1 -1
- data/test/lib/facets/core/symbol/test_capitalize.rb +1 -1
- data/test/lib/facets/core/symbol/test_capitalized.rb +1 -1
- data/test/lib/facets/core/symbol/test_downcase.rb +1 -1
- data/test/lib/facets/core/symbol/test_not.rb +1 -1
- data/test/lib/facets/core/symbol/test_pad.rb +1 -1
- data/test/lib/facets/core/symbol/test_succ.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_const.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_proc.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_str.rb +1 -1
- data/test/lib/facets/core/symbol/test_underscore.rb +1 -1
- data/test/lib/facets/core/symbol/test_upcase.rb +1 -1
- data/test/lib/facets/core/time/test_change.rb +1 -1
- data/test/lib/facets/core/time/test_elapse.rb +1 -1
- data/test/lib/facets/core/time/test_stamp.rb +1 -1
- data/test/lib/facets/core/time/test_to_date.rb +1 -1
- data/test/lib/facets/core/time/test_to_s.rb +1 -1
- data/test/lib/facets/core/time/test_to_time.rb +1 -1
- data/test/lib/facets/more/test_annotation.rb +1 -1
- data/test/lib/facets/more/test_ansicode.rb +1 -1
- data/test/lib/facets/more/test_association.rb +1 -1
- data/test/lib/facets/more/test_basicobject.rb +58 -0
- data/test/lib/facets/more/test_bbcode.rb +1 -1
- data/test/lib/facets/more/test_bitmask.rb +1 -1
- data/test/lib/facets/more/test_bytes.rb +1 -1
- data/test/lib/facets/more/test_classinherit.rb +1 -1
- data/test/lib/facets/more/test_classmethods.rb +1 -1
- data/test/lib/facets/more/test_coroutine.rb +1 -1
- data/test/lib/facets/more/test_crypt.rb +1 -1
- data/test/lib/facets/more/test_dictionary.rb +1 -1
- data/test/lib/facets/more/test_elementor.rb +48 -0
- data/test/lib/facets/more/test_enumerablepass.rb +1 -1
- data/test/lib/facets/more/test_floatstring.rb +1 -1
- data/test/lib/facets/more/test_functor.rb +1 -1
- data/test/lib/facets/more/test_inheritor.rb +1 -1
- data/test/lib/facets/more/test_interval.rb +1 -1
- data/test/lib/facets/more/test_json.rb +232 -0
- data/test/lib/facets/more/test_lisp.rb +1 -1
- data/test/lib/facets/more/test_lisp_format.rb +1 -1
- data/test/lib/facets/more/test_lrucache.rb +1 -1
- data/test/lib/facets/more/test_mathconstants.rb +1 -1
- data/test/lib/facets/more/test_methodprobe.rb +1 -1
- data/test/lib/facets/more/test_multipliers.rb +1 -1
- data/test/lib/facets/more/test_multiton.rb +1 -1
- data/test/lib/facets/more/test_nackclass.rb +1 -1
- data/test/lib/facets/more/test_nilcomparable.rb +6 -2
- data/test/lib/facets/more/test_openobject.rb +1 -1
- data/test/lib/facets/more/test_overload.rb +1 -1
- data/test/lib/facets/more/test_paramix.rb +1 -1
- data/test/lib/facets/more/test_preinitialize.rb +1 -1
- data/test/lib/facets/more/test_promoteself.rb +1 -1
- data/test/lib/facets/more/test_recorder.rb +44 -0
- data/test/lib/facets/more/test_snapshot.rb +1 -1
- data/test/lib/facets/more/test_statichash.rb +1 -1
- data/test/lib/facets/more/test_syncarray.rb +1 -1
- data/test/lib/facets/more/test_synchash.rb +1 -1
- data/test/lib/facets/more/test_tagiterator.rb +1 -1
- data/test/lib/facets/more/test_timer.rb +1 -1
- data/test/lib/facets/more/test_times.rb +1 -1
- data/test/lib/facets/more/test_tuple.rb +1 -1
- data/test/lib/facets/more/test_typecast.rb +2 -2
- data/test/lib/facets/more/test_uninheritable.rb +1 -1
- data/test/lib/facets/more/test_units.rb +16 -10
- data/test/lib/facets/more/test_xoxo.rb +288 -0
- data/test/lib/facets/more/test_yamlstruct.rb +1 -1
- metadata +92 -25
- data/lib/facet/kernel/instance.rb +0 -1
- data/lib/facet/module/cattr.rb +0 -1
- data/lib/facet/module/cattr_accessor.rb +0 -1
- data/lib/facet/module/cattr_reader.rb +0 -1
- data/lib/facet/module/cattr_writer.rb +0 -1
- data/lib/facets/core/kernel/instance.rb +0 -29
- data/test/FIXTURE/create_file +0 -1
- data/test/FIXTURE/open_as_string_file +0 -1
- data/test/FIXTURE/read_list_file +0 -6
- data/test/lib/facets/core/dir/self/test_ls_r.rb +0 -52
- data/test/lib/facets/core/fileutils/test_wc.rb +0 -68
- data/test/lib/facets/core/fileutils/test_which.rb +0 -61
- data/test/testdir.rb +0 -8
data/lib/facets/more/typecast.rb
CHANGED
@@ -13,11 +13,10 @@
|
|
13
13
|
# FOR A PARTICULAR PURPOSE.
|
14
14
|
#
|
15
15
|
# ==========================================================================
|
16
|
-
# Revision
|
16
|
+
# Revision Notes
|
17
17
|
# ==========================================================================
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
18
|
+
# Consider how this might fit in with method signitures, overloading,
|
19
|
+
# and expiremental euphoria-like type system.
|
21
20
|
# ==========================================================================
|
22
21
|
#
|
23
22
|
# TODO : look to implement to_int, to_mailtext, to_r, to_rfc822text and to_str
|
@@ -31,7 +30,7 @@
|
|
31
30
|
# To implement a new type conversion, you have two choices :
|
32
31
|
#
|
33
32
|
# Take :
|
34
|
-
#
|
33
|
+
#
|
35
34
|
# class CustomType
|
36
35
|
# def initialize(my_var)
|
37
36
|
# @my_var = my_var
|
@@ -58,7 +57,7 @@
|
|
58
57
|
# end
|
59
58
|
#
|
60
59
|
# "1234".cast_to CustomType => #<CustomType:0xb7d1958c @my_var="1234">
|
61
|
-
#
|
60
|
+
#
|
62
61
|
#
|
63
62
|
# Those two methods are equivalent in the result. It was coded like that to
|
64
63
|
# avoid the pollution of core classes with tons of to_* methods.
|
@@ -74,7 +73,7 @@
|
|
74
73
|
# == FAQ
|
75
74
|
#
|
76
75
|
# Why didn't you name the `cast_to` method to `to` ?
|
77
|
-
#
|
76
|
+
#
|
78
77
|
# Even if it would make the syntax more friendly, I suspect it could cause
|
79
78
|
# a lot of collisions with already existing code. The goal is that each
|
80
79
|
# time you call cast_to, you either get your result, either a
|
@@ -85,6 +84,8 @@
|
|
85
84
|
# * Jonas Pfenniger
|
86
85
|
#
|
87
86
|
|
87
|
+
require 'time'
|
88
|
+
|
88
89
|
require 'facet/string/methodize'
|
89
90
|
require 'facet/string/modulize'
|
90
91
|
|
@@ -95,6 +96,7 @@ class Object
|
|
95
96
|
# 1234.cast_to(String) => "1234"
|
96
97
|
#
|
97
98
|
def cast_to(klass, options={})
|
99
|
+
# TODO check for a to_{klass.name} here?
|
98
100
|
klass.cast_from(self, options)
|
99
101
|
end
|
100
102
|
|
@@ -118,7 +120,7 @@ class Object
|
|
118
120
|
end
|
119
121
|
|
120
122
|
# Extend the ruby core
|
121
|
-
|
123
|
+
|
122
124
|
class Array
|
123
125
|
class << self
|
124
126
|
def cast_from(object, options={})
|
@@ -185,9 +187,7 @@ class Class
|
|
185
187
|
nil
|
186
188
|
end
|
187
189
|
|
188
|
-
|
189
|
-
|
190
|
-
alias :cast_from_symbol :cast_from_string
|
190
|
+
alias_method :cast_from_symbol, :cast_from_string
|
191
191
|
|
192
192
|
end
|
193
193
|
end
|
@@ -278,7 +278,7 @@ end
|
|
278
278
|
end
|
279
279
|
|
280
280
|
def test_string_to_time
|
281
|
-
assert_equal( "Mon Oct 10 00:00:00
|
281
|
+
assert_equal( "Mon Oct 10 00:00:00 2005", "2005-10-10".cast_to(Time).strftime("%a %b %d %H:%M:%S %Y") )
|
282
282
|
end
|
283
283
|
|
284
284
|
def test_no_converter
|
data/lib/facets/more/units.rb
CHANGED
@@ -436,7 +436,7 @@ module Units
|
|
436
436
|
end
|
437
437
|
|
438
438
|
def driver
|
439
|
-
@@driver ||= SOAP::WSDLDriverFactory.new("http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl").create_rpc_driver
|
439
|
+
@@driver ||= SOAP::WSDLDriverFactory.new("http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl").create_rpc_driver
|
440
440
|
end
|
441
441
|
|
442
442
|
end
|
@@ -797,13 +797,13 @@ module Units
|
|
797
797
|
|
798
798
|
# The directory in which the data files are searched for
|
799
799
|
begin
|
800
|
-
if ::Gem.active?('
|
801
|
-
DATADIR = File.join( ::Gem.gempath('
|
800
|
+
if ::Gem.active?('facets')
|
801
|
+
DATADIR = File.join( ::Gem.gempath('facets'), 'data', 'facets', 'units' )
|
802
802
|
else
|
803
|
-
DATADIR = File.join( ::Config::CONFIG['datadir'], '
|
803
|
+
DATADIR = File.join( ::Config::CONFIG['datadir'], 'facets', 'units' )
|
804
804
|
end
|
805
805
|
rescue
|
806
|
-
DATADIR = File.join( ::Config::CONFIG['datadir'], '
|
806
|
+
DATADIR = File.join( ::Config::CONFIG['datadir'], 'facets', 'units' )
|
807
807
|
end
|
808
808
|
|
809
809
|
# The standard service used for looking up currency exchange rates
|
@@ -920,18 +920,24 @@ end
|
|
920
920
|
end
|
921
921
|
|
922
922
|
def test_01_016
|
923
|
-
|
923
|
+
assert(
|
924
|
+
[:us, :cex, :default, :uk].all? { |c|
|
925
|
+
Converter.registered_converters.include?( c )
|
926
|
+
}
|
927
|
+
)
|
924
928
|
end
|
925
929
|
|
926
|
-
|
927
|
-
assert_raises(TypeError) {
|
928
|
-
1.try.to(usd)
|
929
|
-
}
|
930
|
-
end
|
930
|
+
# Money exchange is off line at the moment
|
931
931
|
|
932
|
-
def
|
933
|
-
|
934
|
-
|
932
|
+
#def test_01_017
|
933
|
+
# assert_raises(TypeError) {
|
934
|
+
# 1.try.to(usd)
|
935
|
+
# }
|
936
|
+
#end
|
937
|
+
|
938
|
+
#def test_01_016
|
939
|
+
# assert_equal( "33.2190007563597 twd", (1.usd(:cex).to(twd(:cex))).to_s )
|
940
|
+
#end
|
935
941
|
|
936
942
|
end
|
937
943
|
|
@@ -0,0 +1,519 @@
|
|
1
|
+
#--
|
2
|
+
# XOXO
|
3
|
+
#
|
4
|
+
# Ported from xoxo.rb at http://chneukirchen.org/repos/xoxo-rb/
|
5
|
+
# Copyright (C) 2006 Christian Neukirchen
|
6
|
+
#
|
7
|
+
# Ruby License
|
8
|
+
#
|
9
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
10
|
+
# software under the same terms as Ruby.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'rexml/parsers/pullparser'
|
18
|
+
|
19
|
+
# XOXO is a Ruby XOXO parser and generator. It provides
|
20
|
+
# a Ruby API similar to Marshal and YAML (though more
|
21
|
+
# specific) to load and dump XOXO[http://microformats.org/wiki/xoxo],
|
22
|
+
# an simple, open outline format written in standard XHTML and
|
23
|
+
# suitable for embedding in (X)HTML, Atom, RSS, and arbitrary XML.
|
24
|
+
|
25
|
+
module XOXO
|
26
|
+
|
27
|
+
# xoxo.rb version number
|
28
|
+
#VERSION = "0.1"
|
29
|
+
|
30
|
+
# Load and return a XOXO structure from the String, IO or StringIO or _xoxo_.
|
31
|
+
#
|
32
|
+
def self.load(xoxo)
|
33
|
+
structs = Parser.new(xoxo).parse.structs
|
34
|
+
while structs.kind_of?(Array) && structs.size == 1
|
35
|
+
structs = structs.first
|
36
|
+
end
|
37
|
+
structs
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return a XOXO string corresponding to the Ruby object +struct+,
|
41
|
+
# translated to the following rules:
|
42
|
+
#
|
43
|
+
# * Arrays become ordered lists <tt><ol></tt>.
|
44
|
+
# * Hashes become definition lists <tt><dl></tt>, keys are
|
45
|
+
# stringified with +to_s+.
|
46
|
+
# * Everything else becomes stringified with +to_s+ and wrapped in
|
47
|
+
# appropriate list elements (<tt><li></tt> or <tt><dt></tt>/<tt><dd></tt>).
|
48
|
+
#
|
49
|
+
# Additionally, you can pass these options on the _options_ hash:
|
50
|
+
# <tt>:html_wrap</tt> => +true+:: Wrap the XOXO with a basic XHTML 1.0
|
51
|
+
# Transitional header.
|
52
|
+
# <tt>:css</tt> => _css_:: Reference _css_ as stylesheet for the
|
53
|
+
# wrapped XOXO document.
|
54
|
+
#
|
55
|
+
def self.dump(struct, options={})
|
56
|
+
struct = [struct] unless struct.kind_of? Array
|
57
|
+
|
58
|
+
if options[:html_wrap]
|
59
|
+
result = <<EOF.strip
|
60
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
|
61
|
+
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
62
|
+
<html xmlns="http://www.w3.org/1999/xhtml"><head profile=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
63
|
+
EOF
|
64
|
+
if options[:css]
|
65
|
+
result << %Q[<style type="text/css" >@import "#{options[:css]}";</style>]
|
66
|
+
end
|
67
|
+
|
68
|
+
result << "</head><body>" << make_xoxo(struct, 'xoxo') << "</body></html>"
|
69
|
+
else
|
70
|
+
result = make_xoxo(struct, 'xoxo')
|
71
|
+
end
|
72
|
+
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def self.make_xoxo(struct, class_name=nil)
|
79
|
+
s = ''
|
80
|
+
case struct
|
81
|
+
when Array
|
82
|
+
if class_name
|
83
|
+
s << %Q[<ol class="#{class_name}">]
|
84
|
+
else
|
85
|
+
s << "<ol>"
|
86
|
+
end
|
87
|
+
struct.each { |item|
|
88
|
+
s << "<li>" << make_xoxo(item) << "</li>"
|
89
|
+
}
|
90
|
+
s << "</ol>"
|
91
|
+
|
92
|
+
when Hash
|
93
|
+
d = struct.dup
|
94
|
+
if d.has_key? 'url'
|
95
|
+
s << '<a href="' << d['url'].to_s << '" '
|
96
|
+
text = d.fetch('text') { d.fetch('title', d['url']) }
|
97
|
+
%w[title rel type].each { |tag|
|
98
|
+
if d.has_key? tag
|
99
|
+
s << tag.to_s << '="' << make_xoxo(d.delete(tag)) << '" '
|
100
|
+
end
|
101
|
+
}
|
102
|
+
s << '>' << make_xoxo(text) << '</a>'
|
103
|
+
d.delete 'text'
|
104
|
+
d.delete 'url'
|
105
|
+
end
|
106
|
+
|
107
|
+
unless d.empty?
|
108
|
+
s << "<dl>"
|
109
|
+
d.each { |key, value|
|
110
|
+
s << "<dt>" << key.to_s << "</dt><dd>" << make_xoxo(value) << "</dd>"
|
111
|
+
}
|
112
|
+
s << "</dl>"
|
113
|
+
end
|
114
|
+
|
115
|
+
when String
|
116
|
+
s << struct
|
117
|
+
|
118
|
+
else
|
119
|
+
s << struct.to_s # too gentle?
|
120
|
+
end
|
121
|
+
|
122
|
+
s
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class XOXO::Parser # :nodoc:
|
127
|
+
CONTAINER_TAGS = %w{dl ol ul}
|
128
|
+
|
129
|
+
attr_reader :structs
|
130
|
+
|
131
|
+
def initialize(xoxo)
|
132
|
+
@parser = REXML::Parsers::PullParser.new(xoxo)
|
133
|
+
|
134
|
+
@textstack = ['']
|
135
|
+
@xostack = []
|
136
|
+
@structs = []
|
137
|
+
@tags = []
|
138
|
+
end
|
139
|
+
|
140
|
+
def parse
|
141
|
+
while @parser.has_next?
|
142
|
+
res = @parser.pull
|
143
|
+
|
144
|
+
if res.start_element?
|
145
|
+
@tags << res[0]
|
146
|
+
|
147
|
+
case res[0]
|
148
|
+
when "a"
|
149
|
+
attrs = normalize_attrs res[1]
|
150
|
+
attrs['url'] = attrs['href']
|
151
|
+
attrs.delete 'href'
|
152
|
+
push attrs
|
153
|
+
@textstack << ''
|
154
|
+
|
155
|
+
when "dl"
|
156
|
+
push({})
|
157
|
+
|
158
|
+
when "ol", "ul"
|
159
|
+
push []
|
160
|
+
|
161
|
+
when "li", "dt", "dd"
|
162
|
+
@textstack << ''
|
163
|
+
|
164
|
+
end
|
165
|
+
elsif res.end_element?
|
166
|
+
@tags.pop
|
167
|
+
|
168
|
+
case res[0]
|
169
|
+
when "a"
|
170
|
+
val = @textstack.pop
|
171
|
+
unless val.empty?
|
172
|
+
val = '' if @xostack.last['title'] == val
|
173
|
+
val = '' if @xostack.last['url'] == val
|
174
|
+
@xostack.last['text'] = val unless val.empty?
|
175
|
+
end
|
176
|
+
@xostack.pop
|
177
|
+
|
178
|
+
when "dl", "ol", "ul"
|
179
|
+
@xostack.pop
|
180
|
+
|
181
|
+
when "li"
|
182
|
+
val = @textstack.pop
|
183
|
+
while @structs.last != @xostack.last
|
184
|
+
val = @structs.pop
|
185
|
+
@xostack.last << val
|
186
|
+
end
|
187
|
+
@xostack.last << val if val.kind_of? String
|
188
|
+
|
189
|
+
when "dt"
|
190
|
+
# skip
|
191
|
+
|
192
|
+
when "dd"
|
193
|
+
val = @textstack.pop
|
194
|
+
key = @textstack.pop
|
195
|
+
|
196
|
+
val = @structs.pop if @structs.last != @xostack.last
|
197
|
+
@xostack.last[key] = val
|
198
|
+
|
199
|
+
end
|
200
|
+
elsif res.text?
|
201
|
+
unless @tags.empty? || CONTAINER_TAGS.include?(@tags.last)
|
202
|
+
@textstack.last << res[0]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
self
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
def normalize_attrs(attrs)
|
213
|
+
attrs.keys.find_all { |k, v| k != k.downcase }.each { |k, v|
|
214
|
+
v = v.downcase if k == "rel" || k == "type"
|
215
|
+
attrs.delete k
|
216
|
+
attrs[k.downcase] = v
|
217
|
+
}
|
218
|
+
attrs
|
219
|
+
end
|
220
|
+
|
221
|
+
def push(struct)
|
222
|
+
if struct == {} && @structs.last.kind_of?(Hash) &&
|
223
|
+
@structs.last.has_key?('url') &&
|
224
|
+
@structs.last != @xostack.last
|
225
|
+
# put back the <a>-made one for extra def's
|
226
|
+
@xostack << @structs.last
|
227
|
+
else
|
228
|
+
@structs << struct
|
229
|
+
@xostack << @structs.last
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
# _____ _
|
237
|
+
# |_ _|__ ___| |_
|
238
|
+
# | |/ _ \/ __| __|
|
239
|
+
# | | __/\__ \ |_
|
240
|
+
# |_|\___||___/\__|
|
241
|
+
#
|
242
|
+
|
243
|
+
=begin test
|
244
|
+
|
245
|
+
require 'test/unit'
|
246
|
+
|
247
|
+
class TCXOXO < Test::Unit::TestCase
|
248
|
+
|
249
|
+
def test_simple_list
|
250
|
+
l = ['1', '2', '3']
|
251
|
+
html = XOXO.dump(l)
|
252
|
+
assert_equal '<ol class="xoxo"><li>1</li><li>2</li><li>3</li></ol>', html
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_nested_list
|
256
|
+
l = ['1', ['2', '3']]
|
257
|
+
assert_equal '<ol class="xoxo"><li>1</li><li><ol><li>2</li><li>3</li></ol></li></ol>', XOXO.dump(l)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_hash
|
261
|
+
h = {'test' => '1', 'name' => 'Kevin'}
|
262
|
+
# Changed since Ruby sorts the hash differently.
|
263
|
+
assert_equal '<ol class="xoxo"><li><dl><dt>name</dt><dd>Kevin</dd><dt>test</dt><dd>1</dd></dl></li></ol>', XOXO.dump(h)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_single_item
|
267
|
+
l = 'test'
|
268
|
+
assert_equal '<ol class="xoxo"><li>test</li></ol>', XOXO.dump(l)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_wrap_differs
|
272
|
+
l = 'test'
|
273
|
+
html = XOXO.dump(l)
|
274
|
+
html_wrap = XOXO.dump(l, :html_wrap => true)
|
275
|
+
assert_not_equal html, html_wrap
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_wrap_single_item
|
279
|
+
l = 'test'
|
280
|
+
html = XOXO.dump(l, :html_wrap => true)
|
281
|
+
assert_equal <<EOF.strip, html
|
282
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
|
283
|
+
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
284
|
+
<html xmlns="http://www.w3.org/1999/xhtml"><head profile=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><ol class="xoxo"><li>test</li></ol></body></html>
|
285
|
+
EOF
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_wrap_item_with_css
|
289
|
+
l = 'test'
|
290
|
+
html = XOXO.dump(l, :html_wrap => true, :css => 'reaptest.css')
|
291
|
+
assert_equal <<EOF.strip, html
|
292
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
|
293
|
+
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
294
|
+
<html xmlns="http://www.w3.org/1999/xhtml"><head profile=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css" >@import "reaptest.css";</style></head><body><ol class="xoxo"><li>test</li></ol></body></html>
|
295
|
+
EOF
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_hash_roundtrip
|
299
|
+
h = {'test' => '1', 'name' => 'Kevin'}
|
300
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_hash_with_url_roundtrip
|
304
|
+
h = {'url' => 'http://example.com', 'name' => 'Kevin'}
|
305
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_nested_hash_roundtrip
|
309
|
+
h = {'test' => '1', 'inner' => {'name' => 'Kevin'}}
|
310
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_nested_hash_with_url_roundtrip
|
314
|
+
h = {'url' => 'http://example.com', 'inner' => {
|
315
|
+
'url' => 'http://slashdot.org', 'name' => 'Kevin'}}
|
316
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_list_round_trip
|
320
|
+
l = ['3', '2', '1']
|
321
|
+
assert_equal l, XOXO.load(XOXO.dump(l))
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_list_of_hashes_round_trip
|
325
|
+
l = ['3', {'a' => '2'}, {'b' => '1', 'c' => '4'}]
|
326
|
+
assert_equal l, XOXO.load(XOXO.dump(l))
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_list_of_lists_round_trip
|
330
|
+
l = ['3', ['a', '2'], ['b', ['1', ['c', '4']]]]
|
331
|
+
assert_equal l, XOXO.load(XOXO.dump(l))
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_hashes_of_lists_roundtrip
|
335
|
+
h = {
|
336
|
+
'test' => ['1', '2'],
|
337
|
+
'name' => 'Kevin',
|
338
|
+
'nestlist' => ['a', ['b', 'c']],
|
339
|
+
'nestdict' => {'e' => '6', 'f' => '7'}
|
340
|
+
}
|
341
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_xoxo_junk_in_containers
|
345
|
+
h = XOXO.load '<ol>bad<li><dl>worse<dt>good</dt><dd>buy</dd> now</dl></li></ol>'
|
346
|
+
assert_equal({'good' => 'buy'}, h)
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_xoxo_junk_in_elements
|
350
|
+
l = XOXO.load '<ol><li>bad<dl><dt>good</dt><dd>buy</dd></dl>worse</li><li>bag<ol><li>OK</li></ol>fish</li></ol>'
|
351
|
+
assert_equal([{'good' => 'buy'}, ['OK']], l)
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_xoxo_with_spaces_and_newlines
|
355
|
+
xoxo_sample = <<EOF.strip
|
356
|
+
<ol class='xoxo'>
|
357
|
+
<li>
|
358
|
+
<dl>
|
359
|
+
<dt>text</dt>
|
360
|
+
<dd>item 1</dd>
|
361
|
+
<dt>description</dt>
|
362
|
+
<dd> This item represents the main point we're trying to make.</dd>
|
363
|
+
<dt>url</dt>
|
364
|
+
<dd>http://example.com/more.xoxo</dd>
|
365
|
+
<dt>title</dt>
|
366
|
+
<dd>title of item 1</dd>
|
367
|
+
<dt>type</dt>
|
368
|
+
<dd>text/xml</dd>
|
369
|
+
<dt>rel</dt>
|
370
|
+
<dd>help</dd>
|
371
|
+
</dl>
|
372
|
+
</li>
|
373
|
+
</ol>
|
374
|
+
EOF
|
375
|
+
h = XOXO.load xoxo_sample
|
376
|
+
h2 = {
|
377
|
+
'text' => 'item 1',
|
378
|
+
'description' => " This item represents the main point we're trying to make.",
|
379
|
+
'url' => 'http://example.com/more.xoxo',
|
380
|
+
'title' => 'title of item 1',
|
381
|
+
'type' => 'text/xml',
|
382
|
+
'rel' => 'help'
|
383
|
+
}
|
384
|
+
assert_equal h2, XOXO.load(xoxo_sample)
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_special_attribute_decoding
|
388
|
+
xoxo_sample = <<EOF.strip
|
389
|
+
<ol class='xoxo'>
|
390
|
+
<li>
|
391
|
+
<dl>
|
392
|
+
<dt>text</dt>
|
393
|
+
<dd>item 1</dd>
|
394
|
+
<dt>url</dt>
|
395
|
+
<dd>http://example.com/more.xoxo</dd>
|
396
|
+
<dt>title</dt>
|
397
|
+
<dd>title of item 1</dd>
|
398
|
+
<dt>type</dt>
|
399
|
+
<dd>text/xml</dd>
|
400
|
+
<dt>rel</dt>
|
401
|
+
<dd>help</dd>
|
402
|
+
</dl>
|
403
|
+
</li>
|
404
|
+
</ol>
|
405
|
+
EOF
|
406
|
+
smart_xoxo_sample = <<EOF.strip
|
407
|
+
<ol class='xoxo'>
|
408
|
+
<li><a href="http://example.com/more.xoxo"
|
409
|
+
title="title of item 1"
|
410
|
+
type="text/xml"
|
411
|
+
rel="help">item 1</a>
|
412
|
+
<!-- note how the "text" property is simply the contents of the <a> element -->
|
413
|
+
</li>
|
414
|
+
</ol>
|
415
|
+
EOF
|
416
|
+
assert_equal XOXO.load(xoxo_sample), XOXO.load(smart_xoxo_sample)
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_special_attribute_and_dl_decoding
|
420
|
+
xoxo_sample = <<EOF.strip
|
421
|
+
<ol class="xoxo">
|
422
|
+
<li>
|
423
|
+
<dl>
|
424
|
+
<dt>text</dt>
|
425
|
+
<dd>item 1</dd>
|
426
|
+
<dt>description</dt>
|
427
|
+
<dd> This item represents the main point we're trying to make.</dd>
|
428
|
+
<dt>url</dt>
|
429
|
+
<dd>http://example.com/more.xoxo</dd>
|
430
|
+
<dt>title</dt>
|
431
|
+
<dd>title of item 1</dd>
|
432
|
+
<dt>type</dt>
|
433
|
+
<dd>text/xml</dd>
|
434
|
+
<dt>rel</dt>
|
435
|
+
<dd>help</dd>
|
436
|
+
</dl>
|
437
|
+
</li>
|
438
|
+
</ol>
|
439
|
+
EOF
|
440
|
+
smart_xoxo_sample = <<EOF.strip
|
441
|
+
<ol class="xoxo">
|
442
|
+
<li><a href="http://example.com/more.xoxo"
|
443
|
+
title="title of item 1"
|
444
|
+
type="text/xml"
|
445
|
+
rel="help">item 1</a>
|
446
|
+
<!-- note how the "text" property is simply the contents of the <a> element -->
|
447
|
+
<dl>
|
448
|
+
<dt>description</dt>
|
449
|
+
<dd> This item represents the main point we're trying to make.</dd>
|
450
|
+
</dl>
|
451
|
+
</li>
|
452
|
+
</ol>
|
453
|
+
EOF
|
454
|
+
assert_equal XOXO.load(xoxo_sample), XOXO.load(smart_xoxo_sample)
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_special_attribute_encode
|
458
|
+
h = {
|
459
|
+
'url' => 'http://example.com/more.xoxo',
|
460
|
+
'title' => 'sample url',
|
461
|
+
'type' => "text/xml",
|
462
|
+
'rel' => 'help',
|
463
|
+
'text' => 'an example'
|
464
|
+
}
|
465
|
+
assert_equal '<ol class="xoxo"><li><a href="http://example.com/more.xoxo" title="sample url" rel="help" type="text/xml" >an example</a></li></ol>', XOXO.dump(h)
|
466
|
+
end
|
467
|
+
|
468
|
+
def test_special_attribute_roundtrip_full
|
469
|
+
h = {
|
470
|
+
'url' => 'http://example.com/more.xoxo',
|
471
|
+
'title' => 'sample url',
|
472
|
+
'type' => "text/xml",
|
473
|
+
'rel' => 'help',
|
474
|
+
'text' => 'an example'
|
475
|
+
}
|
476
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
477
|
+
end
|
478
|
+
|
479
|
+
def test_special_attribute_roundtrip_no_text
|
480
|
+
h = {
|
481
|
+
'url' => 'http://example.com/more.xoxo',
|
482
|
+
'title' => 'sample url',
|
483
|
+
'type' => "text/xml",
|
484
|
+
'rel' => 'help'
|
485
|
+
}
|
486
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_special_attribute_roundtrip_no_text_or_title
|
490
|
+
h = {'url' => 'http://example.com/more.xoxo'}
|
491
|
+
assert_equal h, XOXO.load(XOXO.dump(h))
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_attention_roundtrip
|
495
|
+
kmattn = <<EOF.strip
|
496
|
+
<ol class="xoxo"><li><a href="http://www.boingboing.net/" title="Boing Boing Blog" >Boing Boing Blog</a><dl><dt>alturls</dt><dd><ol><li><a href="http://boingboing.net/rss.xml" >xmlurl</a></li></ol></dd><dt>description</dt><dd>Boing Boing Blog</dd></dl></li><li><a href="http://www.financialcryptography.com/" title="Financial Cryptography" >Financial Cryptography</a><dl><dt>alturls</dt><dd><ol><li><a href="http://www.financialcryptography.com/mt/index.rdf" >xmlurl</a></li></ol></dd><dt>description</dt><dd>Financial Cryptography</dd></dl></li><li><a href="http://hublog.hubmed.org/" title="HubLog" >HubLog</a><dl><dt>alturls</dt><dd><ol><li><a href="http://hublog.hubmed.org/index.xml" >xmlurl</a></li><li><a href="http://hublog.hubmed.org/foaf.rdf" >foafurl</a></li></ol></dd><dt>description</dt><dd>HubLog</dd></dl></li></ol>
|
497
|
+
EOF
|
498
|
+
assert_equal kmattn, XOXO.dump(XOXO.load(kmattn))
|
499
|
+
assert_equal XOXO.load(kmattn), XOXO.load(XOXO.dump(XOXO.load(kmattn)))
|
500
|
+
assert_equal XOXO.dump(XOXO.load(kmattn)),
|
501
|
+
XOXO.dump(XOXO.load(XOXO.dump(XOXO.load(kmattn))))
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_unicode_roundtrip
|
505
|
+
unicode = "Tantek \xc3\x87elik and a snowman \xe2\x98\x83"
|
506
|
+
assert_equal unicode, XOXO.load(XOXO.dump(unicode))
|
507
|
+
end
|
508
|
+
|
509
|
+
# TBD: Implement proper encodings.
|
510
|
+
#
|
511
|
+
# def test_utf8_roundtrip
|
512
|
+
# end
|
513
|
+
# def test_windows1252_roundtrip
|
514
|
+
# end
|
515
|
+
end
|
516
|
+
|
517
|
+
=end
|
518
|
+
|
519
|
+
|