facets 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (400) hide show
  1. data/CHANGELOG +11 -0
  2. data/ProjectInfo +2 -2
  3. data/Rakefile +3 -1
  4. data/conf/facets/noauto +28 -13
  5. data/data/facets/index.yml +3 -4
  6. data/lib/facet/array/pot.rb +1 -0
  7. data/lib/facet/builderobject.rb +1 -0
  8. data/lib/facet/module/this.rb +1 -0
  9. data/lib/facet/rexmlbuilder.rb +1 -0
  10. data/lib/facet/string/pot.rb +1 -0
  11. data/lib/facets/core/array.rb +1 -1
  12. data/lib/facets/core/array/{slap.rb → pot.rb} +8 -7
  13. data/lib/facets/core/date.rb +6 -0
  14. data/lib/facets/core/fileutils.rb +8 -0
  15. data/lib/facets/core/gem.rb +3 -0
  16. data/lib/facets/core/kernel/autoreload.rb +5 -5
  17. data/lib/facets/core/logger.rb +2 -0
  18. data/lib/facets/core/module.rb +1 -1
  19. data/lib/facets/core/module/{let.rb → this.rb} +21 -12
  20. data/lib/facets/core/ostruct.rb +7 -0
  21. data/lib/facets/core/string.rb +1 -2
  22. data/lib/facets/core/string/{slap.rb → pot.rb} +10 -9
  23. data/lib/facets/core/string/to_a.rb +13 -7
  24. data/lib/facets/more/basicobject.rb +2 -0
  25. data/lib/facets/more/builderobject.rb +216 -0
  26. data/lib/facets/more/functor.rb +13 -12
  27. data/lib/facets/more/multiton.rb +5 -5
  28. data/lib/facets/more/progressbar.rb +7 -1
  29. data/lib/facets/more/rexmlbuilder.rb +104 -0
  30. data/lib/facets/more/tuple.rb +219 -55
  31. data/lib/facets/more/units.rb +2 -1
  32. data/test/lib/facets/core/array/test_at_rand.rb +1 -1
  33. data/test/lib/facets/core/array/test_delete_unless.rb +1 -1
  34. data/test/lib/facets/core/array/test_delete_values.rb +1 -1
  35. data/test/lib/facets/core/array/test_delete_values_at.rb +1 -1
  36. data/test/lib/facets/core/array/test_first.rb +1 -1
  37. data/test/lib/facets/core/array/test_head.rb +1 -1
  38. data/test/lib/facets/core/array/test_last_index.rb +1 -1
  39. data/test/lib/facets/core/array/test_merge.rb +1 -1
  40. data/test/lib/facets/core/array/test_mid.rb +1 -1
  41. data/test/lib/facets/core/array/test_middle.rb +1 -1
  42. data/test/lib/facets/core/array/test_op_fetch.rb +1 -1
  43. data/test/lib/facets/core/array/test_op_store.rb +1 -1
  44. data/test/lib/facets/core/array/test_pick.rb +1 -1
  45. data/test/lib/facets/core/array/test_pos.rb +1 -1
  46. data/test/lib/facets/core/array/test_pot.rb +28 -0
  47. data/test/lib/facets/core/array/test_pull.rb +1 -1
  48. data/test/lib/facets/core/array/test_rand_index.rb +1 -1
  49. data/test/lib/facets/core/array/test_rand_subset.rb +1 -1
  50. data/test/lib/facets/core/array/test_range.rb +1 -1
  51. data/test/lib/facets/core/array/test_rotate.rb +1 -1
  52. data/test/lib/facets/core/array/test_select.rb +1 -1
  53. data/test/lib/facets/core/array/test_shuffle.rb +1 -1
  54. data/test/lib/facets/core/array/test_thru.rb +1 -1
  55. data/test/lib/facets/core/array/test_to_b.rb +1 -1
  56. data/test/lib/facets/core/array/test_to_h.rb +1 -1
  57. data/test/lib/facets/core/array/test_to_hash.rb +1 -1
  58. data/test/lib/facets/core/binding/self/test_of_caller.rb +1 -1
  59. data/test/lib/facets/core/binding/test___LINE__.rb +1 -1
  60. data/test/lib/facets/core/binding/test_call_stack.rb +1 -1
  61. data/test/lib/facets/core/binding/test_called.rb +1 -1
  62. data/test/lib/facets/core/binding/test_caller.rb +1 -1
  63. data/test/lib/facets/core/binding/test_defined.rb +1 -1
  64. data/test/lib/facets/core/binding/test_eval.rb +1 -1
  65. data/test/lib/facets/core/binding/test_local_variables.rb +1 -1
  66. data/test/lib/facets/core/binding/test_method_name.rb +1 -1
  67. data/test/lib/facets/core/binding/test_op_fetch.rb +1 -1
  68. data/test/lib/facets/core/binding/test_op_store.rb +1 -1
  69. data/test/lib/facets/core/binding/test_self.rb +1 -1
  70. data/test/lib/facets/core/class/test_cattr.rb +1 -1
  71. data/test/lib/facets/core/class/test_descendents.rb +1 -1
  72. data/test/lib/facets/core/class/test_method_name.rb +1 -1
  73. data/test/lib/facets/core/class/test_remove_descendents.rb +1 -1
  74. data/test/lib/facets/core/class/test_unix_path.rb +1 -1
  75. data/test/lib/facets/core/comparable/test_at_least.rb +1 -1
  76. data/test/lib/facets/core/comparable/test_clip.rb +1 -1
  77. data/test/lib/facets/core/comparable/test_cmp.rb +1 -1
  78. data/test/lib/facets/core/continuation/self/test_create.rb +1 -1
  79. data/test/lib/facets/core/date/test_days_in_month.rb +1 -1
  80. data/test/lib/facets/core/date/test_days_of_month.rb +1 -1
  81. data/test/lib/facets/core/date/test_stamp.rb +1 -1
  82. data/test/lib/facets/core/date/test_to_date.rb +1 -1
  83. data/test/lib/facets/core/date/test_to_s.rb +1 -1
  84. data/test/lib/facets/core/date/test_to_time.rb +1 -1
  85. data/test/lib/facets/core/dir/self/test_ancestor.rb +1 -1
  86. data/test/lib/facets/core/dir/self/test_ascend.rb +1 -1
  87. data/test/lib/facets/core/enumerable/self/test_combinations.rb +1 -1
  88. data/test/lib/facets/core/enumerable/self/test_cross.rb +1 -1
  89. data/test/lib/facets/core/enumerable/test_collect_with_index.rb +1 -1
  90. data/test/lib/facets/core/enumerable/test_commonality.rb +1 -1
  91. data/test/lib/facets/core/enumerable/test_compact_collect.rb +1 -1
  92. data/test/lib/facets/core/enumerable/test_cross.rb +1 -1
  93. data/test/lib/facets/core/enumerable/test_each_combination.rb +1 -1
  94. data/test/lib/facets/core/enumerable/test_each_pair.rb +1 -1
  95. data/test/lib/facets/core/enumerable/test_each_slice.rb +1 -1
  96. data/test/lib/facets/core/enumerable/test_each_unique_pair.rb +1 -1
  97. data/test/lib/facets/core/enumerable/test_entropy.rb +1 -1
  98. data/test/lib/facets/core/enumerable/test_every.rb +1 -1
  99. data/test/lib/facets/core/enumerable/test_ew.rb +1 -1
  100. data/test/lib/facets/core/enumerable/test_filter_collect.rb +1 -1
  101. data/test/lib/facets/core/enumerable/test_find_collisions.rb +1 -1
  102. data/test/lib/facets/core/enumerable/test_frequency.rb +1 -1
  103. data/test/lib/facets/core/enumerable/test_graph.rb +1 -1
  104. data/test/lib/facets/core/enumerable/test_ideal_entropy.rb +1 -1
  105. data/test/lib/facets/core/enumerable/test_none.rb +1 -1
  106. data/test/lib/facets/core/enumerable/test_occur.rb +1 -1
  107. data/test/lib/facets/core/enumerable/test_one.rb +1 -1
  108. data/test/lib/facets/core/enumerable/test_op_pow.rb +1 -1
  109. data/test/lib/facets/core/enumerable/test_partition_by.rb +1 -1
  110. data/test/lib/facets/core/enumerable/test_permute.rb +1 -1
  111. data/test/lib/facets/core/enumerable/test_probability.rb +1 -1
  112. data/test/lib/facets/core/enumerable/test_to_h.rb +1 -1
  113. data/test/lib/facets/core/enumerable/test_uniq_by.rb +1 -1
  114. data/test/lib/facets/core/file/self/test_create.rb +1 -1
  115. data/test/lib/facets/core/file/self/test_open_as_string.rb +1 -1
  116. data/test/lib/facets/core/file/self/test_read_list.rb +1 -1
  117. data/test/lib/facets/core/file/self/test_sanitize.rb +1 -1
  118. data/test/lib/facets/core/file/self/test_split_all.rb +1 -1
  119. data/test/lib/facets/core/float/test_round_at.rb +1 -1
  120. data/test/lib/facets/core/float/test_round_to.rb +1 -1
  121. data/test/lib/facets/core/hash/self/test_zipnew.rb +1 -1
  122. data/test/lib/facets/core/hash/test_alias.rb +1 -1
  123. data/test/lib/facets/core/hash/test_assert_has_keys.rb +1 -1
  124. data/test/lib/facets/core/hash/test_assert_has_only_keys.rb +1 -1
  125. data/test/lib/facets/core/hash/test_at.rb +1 -1
  126. data/test/lib/facets/core/hash/test_collate.rb +1 -1
  127. data/test/lib/facets/core/hash/test_each.rb +1 -1
  128. data/test/lib/facets/core/hash/test_each_with_index.rb +1 -1
  129. data/test/lib/facets/core/hash/test_each_with_key.rb +1 -1
  130. data/test/lib/facets/core/hash/test_graph.rb +1 -1
  131. data/test/lib/facets/core/hash/test_has_keys.rb +1 -1
  132. data/test/lib/facets/core/hash/test_has_only_keys.rb +1 -1
  133. data/test/lib/facets/core/hash/test_inverse.rb +1 -1
  134. data/test/lib/facets/core/hash/test_keys_to_s.rb +1 -1
  135. data/test/lib/facets/core/hash/test_keys_to_sym.rb +1 -1
  136. data/test/lib/facets/core/hash/test_op_fetch.rb +1 -1
  137. data/test/lib/facets/core/hash/test_op_lshift.rb +1 -1
  138. data/test/lib/facets/core/hash/test_rand_key.rb +1 -1
  139. data/test/lib/facets/core/hash/test_rand_pair.rb +1 -1
  140. data/test/lib/facets/core/hash/test_rand_value.rb +1 -1
  141. data/test/lib/facets/core/hash/test_replace_each.rb +1 -1
  142. data/test/lib/facets/core/hash/test_shuffle.rb +1 -1
  143. data/test/lib/facets/core/hash/test_slice.rb +1 -1
  144. data/test/lib/facets/core/hash/test_swap.rb +1 -1
  145. data/test/lib/facets/core/hash/test_swapkey.rb +1 -1
  146. data/test/lib/facets/core/hash/test_to_h.rb +1 -1
  147. data/test/lib/facets/core/hash/test_to_ostruct.rb +1 -1
  148. data/test/lib/facets/core/hash/test_to_ostruct_recurse.rb +1 -1
  149. data/test/lib/facets/core/hash/test_traverse.rb +1 -1
  150. data/test/lib/facets/core/hash/test_update_each.rb +1 -1
  151. data/test/lib/facets/core/hash/test_update_keys.rb +1 -1
  152. data/test/lib/facets/core/hash/test_update_values.rb +1 -1
  153. data/test/lib/facets/core/hash/test_weave.rb +1 -1
  154. data/test/lib/facets/core/integer/test_factorial.rb +1 -1
  155. data/test/lib/facets/core/integer/test_multiple.rb +1 -1
  156. data/test/lib/facets/core/integer/test_ordinal.rb +1 -1
  157. data/test/lib/facets/core/integer/test_times_collect.rb +1 -1
  158. data/test/lib/facets/core/kernel/test___class__.rb +1 -1
  159. data/test/lib/facets/core/kernel/test_as.rb +1 -1
  160. data/test/lib/facets/core/kernel/test_assign_from.rb +1 -1
  161. data/test/lib/facets/core/kernel/test_assign_with.rb +1 -1
  162. data/test/lib/facets/core/kernel/test_bool.rb +1 -1
  163. data/test/lib/facets/core/kernel/test_bug.rb +1 -1
  164. data/test/lib/facets/core/kernel/test_call_stack.rb +1 -1
  165. data/test/lib/facets/core/kernel/test_called.rb +1 -1
  166. data/test/lib/facets/core/kernel/test_constant.rb +1 -1
  167. data/test/lib/facets/core/kernel/test_copy.rb +1 -1
  168. data/test/lib/facets/core/kernel/test_deep_copy.rb +1 -1
  169. data/test/lib/facets/core/kernel/test_demo.rb +1 -1
  170. data/test/lib/facets/core/kernel/test_fn.rb +1 -1
  171. data/test/lib/facets/core/kernel/test_generate_method_name.rb +1 -1
  172. data/test/lib/facets/core/kernel/test_get_by_id.rb +1 -1
  173. data/test/lib/facets/core/kernel/test_here.rb +1 -1
  174. data/test/lib/facets/core/kernel/test_in.rb +1 -1
  175. data/test/lib/facets/core/kernel/test_maybe.rb +1 -1
  176. data/test/lib/facets/core/kernel/test_metaclass.rb +1 -1
  177. data/test/lib/facets/core/kernel/test_method.rb +1 -1
  178. data/test/lib/facets/core/kernel/test_methodname.rb +1 -1
  179. data/test/lib/facets/core/kernel/test_methods.rb +1 -1
  180. data/test/lib/facets/core/kernel/test_new.rb +1 -1
  181. data/test/lib/facets/core/kernel/test_object_class.rb +1 -1
  182. data/test/lib/facets/core/kernel/test_object_hexid.rb +1 -1
  183. data/test/lib/facets/core/kernel/test_require_all.rb +1 -1
  184. data/test/lib/facets/core/kernel/test_require_esc.rb +1 -1
  185. data/test/lib/facets/core/kernel/test_require_facet.rb +1 -1
  186. data/test/lib/facets/core/kernel/test_resc.rb +1 -1
  187. data/test/lib/facets/core/kernel/test_returning.rb +1 -1
  188. data/test/lib/facets/core/kernel/test_send_as.rb +1 -1
  189. data/test/lib/facets/core/kernel/test_set_from.rb +1 -1
  190. data/test/lib/facets/core/kernel/test_set_with.rb +1 -1
  191. data/test/lib/facets/core/kernel/test_silently.rb +1 -1
  192. data/test/lib/facets/core/kernel/test_singleton.rb +1 -1
  193. data/test/lib/facets/core/kernel/test_superior.rb +1 -1
  194. data/test/lib/facets/core/kernel/test_supermethod.rb +1 -1
  195. data/test/lib/facets/core/kernel/test_this.rb +1 -1
  196. data/test/lib/facets/core/kernel/test_to_b.rb +1 -1
  197. data/test/lib/facets/core/kernel/test_to_bool.rb +1 -1
  198. data/test/lib/facets/core/kernel/test_uri.rb +1 -1
  199. data/test/lib/facets/core/kernel/test_val.rb +1 -1
  200. data/test/lib/facets/core/kernel/test_with_accessor.rb +1 -1
  201. data/test/lib/facets/core/matchdata/test_match.rb +1 -1
  202. data/test/lib/facets/core/matchdata/test_matchtree.rb +1 -1
  203. data/test/lib/facets/core/module/test_abstract.rb +1 -1
  204. data/test/lib/facets/core/module/test_alias_module_function.rb +1 -1
  205. data/test/lib/facets/core/module/test_ancestor.rb +1 -1
  206. data/test/lib/facets/core/module/test_basename.rb +1 -1
  207. data/test/lib/facets/core/module/test_by_name.rb +1 -1
  208. data/test/lib/facets/core/module/test_clone_using.rb +1 -1
  209. data/test/lib/facets/core/module/test_dirname.rb +1 -1
  210. data/test/lib/facets/core/module/test_equate_on.rb +1 -1
  211. data/test/lib/facets/core/module/test_generate_instance_method_name.rb +1 -1
  212. data/test/lib/facets/core/module/test_include_as.rb +1 -1
  213. data/test/lib/facets/core/module/test_inherit.rb +1 -1
  214. data/test/lib/facets/core/module/test_initializer.rb +1 -1
  215. data/test/lib/facets/core/module/test_instance_methods.rb +1 -1
  216. data/test/lib/facets/core/module/test_integrate.rb +1 -1
  217. data/test/lib/facets/core/module/test_let.rb +1 -1
  218. data/test/lib/facets/core/module/test_mattr.rb +1 -1
  219. data/test/lib/facets/core/module/test_memoize.rb +1 -1
  220. data/test/lib/facets/core/module/test_modspace.rb +1 -1
  221. data/test/lib/facets/core/module/test_namespace.rb +1 -1
  222. data/test/lib/facets/core/module/test_nesting.rb +1 -1
  223. data/test/lib/facets/core/module/test_on_included.rb +1 -1
  224. data/test/lib/facets/core/module/test_redef.rb +1 -1
  225. data/test/lib/facets/core/module/test_redefine_method.rb +1 -1
  226. data/test/lib/facets/core/module/test_redirect.rb +1 -1
  227. data/test/lib/facets/core/module/test_redirect_method.rb +1 -1
  228. data/test/lib/facets/core/module/test_remove.rb +1 -1
  229. data/test/lib/facets/core/module/test_rename.rb +1 -1
  230. data/test/lib/facets/core/module/test_rename_method.rb +1 -1
  231. data/test/lib/facets/core/module/test_revisal.rb +1 -1
  232. data/test/lib/facets/core/module/test_shadow_method.rb +1 -1
  233. data/test/lib/facets/core/module/test_sort_on.rb +1 -1
  234. data/test/lib/facets/core/module/test_this.rb +31 -0
  235. data/test/lib/facets/core/module/test_undef.rb +1 -1
  236. data/test/lib/facets/core/module/test_wrap.rb +1 -1
  237. data/test/lib/facets/core/module/test_wrap_method.rb +1 -1
  238. data/test/lib/facets/core/nilclass/test_blank.rb +1 -1
  239. data/test/lib/facets/core/nilclass/test_empty.rb +1 -1
  240. data/test/lib/facets/core/nilclass/test_include.rb +1 -1
  241. data/test/lib/facets/core/nilclass/test_op_fetch.rb +1 -1
  242. data/test/lib/facets/core/nilclass/test_size.rb +1 -1
  243. data/test/lib/facets/core/nilclass/test_to_h.rb +1 -1
  244. data/test/lib/facets/core/numeric/test_approx.rb +1 -1
  245. data/test/lib/facets/core/numeric/test_ceil_multiple.rb +1 -1
  246. data/test/lib/facets/core/numeric/test_succ.rb +1 -1
  247. data/test/lib/facets/core/numeric/test_to_b.rb +1 -1
  248. data/test/lib/facets/core/ostruct/test___merge__.rb +1 -1
  249. data/test/lib/facets/core/ostruct/test___update__.rb +1 -1
  250. data/test/lib/facets/core/ostruct/test_op_fetch.rb +1 -1
  251. data/test/lib/facets/core/ostruct/test_op_store.rb +1 -1
  252. data/test/lib/facets/core/proc/test_compose.rb +1 -1
  253. data/test/lib/facets/core/proc/test_to_method.rb +1 -1
  254. data/test/lib/facets/core/range/test_to_r.rb +1 -1
  255. data/test/lib/facets/core/range/test_to_range.rb +1 -1
  256. data/test/lib/facets/core/range/test_umbrella.rb +1 -1
  257. data/test/lib/facets/core/range/test_within.rb +1 -1
  258. data/test/lib/facets/core/regexp/test_arity.rb +1 -1
  259. data/test/lib/facets/core/regexp/test_to_re.rb +1 -1
  260. data/test/lib/facets/core/regexp/test_to_regexp.rb +1 -1
  261. data/test/lib/facets/core/string/self/test_interpolate.rb +1 -1
  262. data/test/lib/facets/core/string/self/test_patterns.rb +1 -1
  263. data/test/lib/facets/core/string/self/test_rand_letter.rb +1 -1
  264. data/test/lib/facets/core/string/test_align_center.rb +1 -1
  265. data/test/lib/facets/core/string/test_at_rand.rb +1 -1
  266. data/test/lib/facets/core/string/test_basename.rb +1 -1
  267. data/test/lib/facets/core/string/test_blank.rb +1 -1
  268. data/test/lib/facets/core/string/test_bracket.rb +1 -1
  269. data/test/lib/facets/core/string/test_camelcase.rb +1 -1
  270. data/test/lib/facets/core/string/test_camelize.rb +1 -1
  271. data/test/lib/facets/core/string/test_capitalized.rb +1 -1
  272. data/test/lib/facets/core/string/test_chars.rb +1 -1
  273. data/test/lib/facets/core/string/test_cmp.rb +1 -1
  274. data/test/lib/facets/core/string/test_demodulize.rb +1 -1
  275. data/test/lib/facets/core/string/test_downcase.rb +1 -1
  276. data/test/lib/facets/core/string/test_dresner.rb +1 -1
  277. data/test/lib/facets/core/string/test_each_char.rb +1 -1
  278. data/test/lib/facets/core/string/test_each_word.rb +1 -1
  279. data/test/lib/facets/core/string/test_first.rb +1 -1
  280. data/test/lib/facets/core/string/test_fold.rb +1 -1
  281. data/test/lib/facets/core/string/test_frequency.rb +1 -1
  282. data/test/lib/facets/core/string/test_humanize.rb +1 -1
  283. data/test/lib/facets/core/string/test_indent.rb +1 -1
  284. data/test/lib/facets/core/string/test_index_all.rb +1 -1
  285. data/test/lib/facets/core/string/test_last.rb +1 -1
  286. data/test/lib/facets/core/string/test_line_wrap.rb +1 -1
  287. data/test/lib/facets/core/string/test_lines.rb +1 -1
  288. data/test/lib/facets/core/string/test_lowercase.rb +1 -1
  289. data/test/lib/facets/core/string/test_margin.rb +1 -1
  290. data/test/lib/facets/core/string/test_methodize.rb +1 -1
  291. data/test/lib/facets/core/string/test_modulize.rb +1 -1
  292. data/test/lib/facets/core/string/test_mscan.rb +1 -1
  293. data/test/lib/facets/core/string/test_natcmp.rb +1 -1
  294. data/test/lib/facets/core/string/test_nchar.rb +1 -1
  295. data/test/lib/facets/core/string/test_pathize.rb +1 -1
  296. data/test/lib/facets/core/string/test_pop.rb +1 -1
  297. data/test/lib/facets/core/string/test_pot.rb +39 -0
  298. data/test/lib/facets/core/string/test_probability.rb +1 -1
  299. data/test/lib/facets/core/string/test_push.rb +1 -1
  300. data/test/lib/facets/core/string/test_quote.rb +1 -1
  301. data/test/lib/facets/core/string/test_rand_byte.rb +1 -1
  302. data/test/lib/facets/core/string/test_rand_index.rb +1 -1
  303. data/test/lib/facets/core/string/test_range.rb +1 -1
  304. data/test/lib/facets/core/string/test_range_all.rb +1 -1
  305. data/test/lib/facets/core/string/test_range_of_line.rb +1 -1
  306. data/test/lib/facets/core/string/test_regesc.rb +1 -1
  307. data/test/lib/facets/core/string/test_shatter.rb +1 -1
  308. data/test/lib/facets/core/string/test_shift.rb +1 -1
  309. data/test/lib/facets/core/string/test_shuffle.rb +1 -1
  310. data/test/lib/facets/core/string/test_similarity.rb +1 -1
  311. data/test/lib/facets/core/string/test_singular.rb +1 -1
  312. data/test/lib/facets/core/string/test_soundex.rb +1 -1
  313. data/test/lib/facets/core/string/test_succ.rb +1 -1
  314. data/test/lib/facets/core/string/test_to_a.rb +1 -1
  315. data/test/lib/facets/core/string/test_to_b.rb +1 -1
  316. data/test/lib/facets/core/string/test_to_const.rb +1 -1
  317. data/test/lib/facets/core/string/test_to_date.rb +1 -1
  318. data/test/lib/facets/core/string/test_to_proc.rb +1 -1
  319. data/test/lib/facets/core/string/test_to_re.rb +1 -1
  320. data/test/lib/facets/core/string/test_to_time.rb +1 -1
  321. data/test/lib/facets/core/string/test_unix_crypt.rb +1 -1
  322. data/test/lib/facets/core/string/test_unpack.rb +1 -1
  323. data/test/lib/facets/core/string/test_unshift.rb +1 -1
  324. data/test/lib/facets/core/string/test_upcase.rb +1 -1
  325. data/test/lib/facets/core/string/test_whitespace.rb +1 -1
  326. data/test/lib/facets/core/string/test_word_filter.rb +1 -1
  327. data/test/lib/facets/core/string/test_word_wrap.rb +1 -1
  328. data/test/lib/facets/core/string/test_words.rb +1 -1
  329. data/test/lib/facets/core/symbol/test_camelcase.rb +1 -1
  330. data/test/lib/facets/core/symbol/test_camelize.rb +1 -1
  331. data/test/lib/facets/core/symbol/test_capitalize.rb +1 -1
  332. data/test/lib/facets/core/symbol/test_capitalized.rb +1 -1
  333. data/test/lib/facets/core/symbol/test_downcase.rb +1 -1
  334. data/test/lib/facets/core/symbol/test_not.rb +1 -1
  335. data/test/lib/facets/core/symbol/test_pad.rb +1 -1
  336. data/test/lib/facets/core/symbol/test_succ.rb +1 -1
  337. data/test/lib/facets/core/symbol/test_to_const.rb +1 -1
  338. data/test/lib/facets/core/symbol/test_to_proc.rb +1 -1
  339. data/test/lib/facets/core/symbol/test_to_str.rb +1 -1
  340. data/test/lib/facets/core/symbol/test_underscore.rb +1 -1
  341. data/test/lib/facets/core/symbol/test_upcase.rb +1 -1
  342. data/test/lib/facets/core/time/test_change.rb +1 -1
  343. data/test/lib/facets/core/time/test_elapse.rb +1 -1
  344. data/test/lib/facets/core/time/test_stamp.rb +1 -1
  345. data/test/lib/facets/core/time/test_to_date.rb +1 -1
  346. data/test/lib/facets/core/time/test_to_s.rb +1 -1
  347. data/test/lib/facets/core/time/test_to_time.rb +1 -1
  348. data/test/lib/facets/more/test_annotation.rb +1 -1
  349. data/test/lib/facets/more/test_ansicode.rb +1 -1
  350. data/test/lib/facets/more/test_association.rb +1 -1
  351. data/test/lib/facets/more/test_basicobject.rb +1 -1
  352. data/test/lib/facets/more/test_bbcode.rb +1 -1
  353. data/test/lib/facets/more/test_bitmask.rb +1 -1
  354. data/test/lib/facets/more/test_bytes.rb +1 -1
  355. data/test/lib/facets/more/test_classinherit.rb +1 -1
  356. data/test/lib/facets/more/test_classmethods.rb +1 -1
  357. data/test/lib/facets/more/test_coroutine.rb +1 -1
  358. data/test/lib/facets/more/test_crypt.rb +1 -1
  359. data/test/lib/facets/more/test_dictionary.rb +1 -1
  360. data/test/lib/facets/more/test_elementor.rb +1 -1
  361. data/test/lib/facets/more/test_enumerablepass.rb +1 -1
  362. data/test/lib/facets/more/test_floatstring.rb +1 -1
  363. data/test/lib/facets/more/test_functor.rb +1 -1
  364. data/test/lib/facets/more/test_inheritor.rb +1 -1
  365. data/test/lib/facets/more/test_interval.rb +1 -1
  366. data/test/lib/facets/more/test_json.rb +1 -1
  367. data/test/lib/facets/more/test_lisp.rb +1 -1
  368. data/test/lib/facets/more/test_lisp_format.rb +1 -1
  369. data/test/lib/facets/more/test_lrucache.rb +1 -1
  370. data/test/lib/facets/more/test_mathconstants.rb +1 -1
  371. data/test/lib/facets/more/test_methodprobe.rb +1 -1
  372. data/test/lib/facets/more/test_multipliers.rb +1 -1
  373. data/test/lib/facets/more/test_multiton.rb +1 -1
  374. data/test/lib/facets/more/test_nackclass.rb +1 -1
  375. data/test/lib/facets/more/test_nilcomparable.rb +1 -1
  376. data/test/lib/facets/more/test_openobject.rb +1 -1
  377. data/test/lib/facets/more/test_overload.rb +1 -1
  378. data/test/lib/facets/more/test_paramix.rb +1 -1
  379. data/test/lib/facets/more/test_preinitialize.rb +1 -1
  380. data/test/lib/facets/more/test_promoteself.rb +1 -1
  381. data/test/lib/facets/more/test_recorder.rb +1 -1
  382. data/test/lib/facets/more/test_snapshot.rb +1 -1
  383. data/test/lib/facets/more/test_statichash.rb +1 -1
  384. data/test/lib/facets/more/test_syncarray.rb +1 -1
  385. data/test/lib/facets/more/test_synchash.rb +1 -1
  386. data/test/lib/facets/more/test_tagiterator.rb +1 -1
  387. data/test/lib/facets/more/test_timer.rb +1 -1
  388. data/test/lib/facets/more/test_times.rb +1 -1
  389. data/test/lib/facets/more/test_tuple.rb +32 -8
  390. data/test/lib/facets/more/test_typecast.rb +1 -1
  391. data/test/lib/facets/more/test_uninheritable.rb +1 -1
  392. data/test/lib/facets/more/test_units.rb +3 -2
  393. data/test/lib/facets/more/test_xoxo.rb +1 -1
  394. data/test/lib/facets/more/test_yamlstruct.rb +1 -1
  395. metadata +15 -10
  396. data/lib/facet/array/slap.rb +0 -1
  397. data/lib/facet/module/let.rb +0 -1
  398. data/lib/facet/string/slap.rb +0 -1
  399. data/lib/facet/string/to_arr.rb +0 -1
  400. data/lib/facets/core/string/to_arr.rb +0 -55
@@ -70,6 +70,8 @@ require 'facets/core/kernel/__class__'
70
70
 
71
71
  class BasicObject
72
72
 
73
+ alias_method :__method__, :method
74
+
73
75
  #EXCLUDE = /^(__id__|__send__)$/
74
76
  EXCLUDE = /(^__|^instance_|^object_|^null$|^inspect$|^dup$|\?$)/
75
77
 
@@ -0,0 +1,216 @@
1
+ #--
2
+ # BuilderFactory
3
+ # Copyright (c) 2006 Thomas Sawyer
4
+ #
5
+ # Ruby License
6
+ #
7
+ #++
8
+
9
+ require 'rexml/document'
10
+
11
+ require 'facets/core/hash/keys_to_s'
12
+ require 'facets/core/kernel/own'
13
+ require 'facets/more/functor' # already requires basicobject
14
+
15
+ # :title: BuilderObject
16
+ #
17
+ # Build structures programatically with Ruby and Ruby's blocks.
18
+ #
19
+ # Builders can use either an implict or explicit receiver.
20
+ # Explicit is the default. To use implicit pass the :implicit
21
+ # option to the constructor.
22
+ #
23
+ # Implict building is more elegant in form, but it is not as
24
+ # functional because it makes it more difficult to refer to
25
+ # external references.
26
+ #
27
+ # BuilderObject avoides metrhod name clashes by using
28
+ # Functor redirection. Unlike other implementations of
29
+ # the Builder patterns which append '!' to builder methods
30
+ # or simply use odd names to avoid clashes, BuilderObject
31
+ # routes all builder method vis the #out method.
32
+ #
33
+ # NOTE The name of this method (#out) may be changed.
34
+
35
+ class BuilderObject < BasicObject
36
+
37
+ # Builder mixin.
38
+
39
+ def self.builder
40
+ @builder ||= Module.new
41
+ end
42
+
43
+ def self.builder_include( *mod )
44
+ builder.module_eval { extend *mod }
45
+ end
46
+
47
+ private
48
+
49
+ def builder
50
+ self.__class__.builder
51
+ end
52
+
53
+ # Prepare builder.
54
+
55
+ def initialize( *options )
56
+ # initialize options
57
+ @options = (Hash === options.last ? options.pop : {} )
58
+ options.each { |o| @options[o] = true }
59
+ # initialize stack
60
+ @stack = []
61
+ # initialize buffer
62
+ @target = builder.new( @options )
63
+ end
64
+
65
+ # Core of Builder's functionality.
66
+
67
+ def method_missing( tag, *args, &block )
68
+ if @current and block_given?
69
+ @stack << @target
70
+ @target = @current
71
+ if @options[:implicit]
72
+ instance_eval( &block )
73
+ else
74
+ block.call
75
+ end
76
+ @target = @stack.pop
77
+ end
78
+ @target
79
+ end
80
+
81
+ # Creates object via builder modules,
82
+ # stores as current and appends to buffer.
83
+
84
+ def +( op, *args, &blk )
85
+ obj = builder.send( op, *args, &blk )
86
+ @current = obj
87
+ @target << obj
88
+ self
89
+ end
90
+
91
+ public
92
+
93
+ # raw insert
94
+
95
+ def <<( str )
96
+ r = builder.raw( str )
97
+ if Array === r
98
+ r.each { |e| @target << e }
99
+ else
100
+ @target << r
101
+ end
102
+ self
103
+ end
104
+
105
+ # Redirection functor.
106
+ #--
107
+ # TODO Better name?
108
+ #++
109
+
110
+ def out( str=nil )
111
+ if str
112
+ self << str
113
+ else
114
+ @builder_functor ||= Functor.new( &__method__(:+) )
115
+ end
116
+ end
117
+
118
+ # text output
119
+
120
+ def to_s
121
+ @target.to_s
122
+ end
123
+
124
+ end
125
+
126
+
127
+ # Some prebuilt mixin modules for creating builders.
128
+ # These could also be used without builder.
129
+
130
+ module BuilderObject::REXML
131
+
132
+ extend self
133
+
134
+ # Add raw XML markup
135
+
136
+ def raw( str )
137
+ REXML::Document.new( "<root>#{str}</root>" ).root.to_a
138
+ end
139
+
140
+ # New REXML document.
141
+
142
+ def document( options={} )
143
+ @options = options
144
+ doc = REXML::Document.new
145
+ # xml declaration
146
+ if options[:version]
147
+ doc << xml(
148
+ options[:version],
149
+ options[:encoding],
150
+ options[:standalone]
151
+ )
152
+ end
153
+ doc
154
+ end
155
+
156
+ # Used for initial buffer value in a builder.
157
+
158
+ alias_method :new, :document
159
+
160
+ # XML declaration
161
+
162
+ def xml( version=nil, *args )
163
+ REXML::XMLDecl.new( version=nil, *args )
164
+ end
165
+
166
+ def element( tag, *args )
167
+ keys = (Hash === args.last ? args.pop : {})
168
+ e = REXML::Element.new( tag )
169
+ e.add_attributes( keys.keys_to_s )
170
+ e.add_text(args.join(' ')) unless args.empty?
171
+ e
172
+ end
173
+
174
+ def instruct( name, *args )
175
+ keys = (Hash === args.last ? args.pop : {})
176
+ content = ( args + keys.collect{ |k,v| %{#{k}="#{v}"} } ).join(' ')
177
+ REXML::Instruction.new( name, content.strip )
178
+ end
179
+ alias_method :instruction, :instruct
180
+ alias_method :pi, :instruct
181
+
182
+ def text( str, *args )
183
+ REXML::Text.new( str, *args )
184
+ end
185
+
186
+ def comment( str, *args )
187
+ REXML::Comment.new( str, *args )
188
+ end
189
+
190
+ def cdata( str, *args )
191
+ REXML::CData.new( str, *args )
192
+ end
193
+
194
+ # DTD declarations
195
+
196
+ def doctype!( *args )
197
+ REXML::DocType.new( *args )
198
+ end
199
+
200
+ def element!( *args )
201
+ REXML::ElementDecl.new( *args )
202
+ end
203
+
204
+ def attlist!( *args )
205
+ REXML::AttlistDecl.new( *args )
206
+ end
207
+
208
+ def entity!( *args )
209
+ REXML::EntityDecl.new( *args )
210
+ end
211
+
212
+ def notation!( *args )
213
+ REXML::NotationDecl.new( *args )
214
+ end
215
+
216
+ end
@@ -14,10 +14,13 @@
14
14
  # ==========================================================================
15
15
  # Revision History
16
16
  # ==========================================================================
17
- # 05-09-22 trans
17
+ # 2006-04-15
18
+ # Code cleanup, changed instance_objects to instance_targets.
19
+ #
20
+ # 2005-09-22 trans
18
21
  # Made a subclass of BasicObject.
19
22
  #
20
- # 05-01-10 trans
23
+ # 2005-01-10 trans
21
24
  # Ported to Facets.
22
25
  # ==========================================================================
23
26
  #++
@@ -33,8 +36,6 @@ require 'facets/more/basicobject'
33
36
  #
34
37
  # == Synopsis
35
38
  #
36
- # require 'mega/functor'
37
- #
38
39
  # f = Functor.new { |op, x| x.send(op, x) }
39
40
  # f + 1 #=> 2
40
41
  # f + 2 #=> 4
@@ -50,22 +51,22 @@ require 'facets/more/basicobject'
50
51
 
51
52
  class Functor < BasicObject
52
53
 
53
- def initialize(*obj, &func)
54
- @obj = obj
55
- @func = func
54
+ def initialize(*targets, &function)
55
+ @targets = targets
56
+ @function = function
56
57
  end
57
58
 
58
59
  def method_missing(op, *args, &blk)
59
60
  if block_given?
60
- @func.call(op, *(@obj + args + [blk]))
61
+ @function.call(op, *(@targets + args), &blk)
61
62
  else
62
- @func.call(op, *(@obj + args))
63
+ @function.call(op, *(@targets + args))
63
64
  end
64
65
  end
65
66
 
66
- def instance_objects
67
- return obj
68
- end
67
+ def instance_targets ; @targets ; end
68
+ def instance_objects ; @targets ; end # deprecate?
69
+ def instance_function; @function ; end
69
70
 
70
71
  end
71
72
 
@@ -80,8 +80,8 @@
80
80
  # A limitation of this approach is that it is impossible to
81
81
  # detect if different blocks were given to a contructor (if it takes a
82
82
  # block). So it is the constructor arguments _only_ which determine
83
- # the uniqueness of an object. A workaround is for the class to define
84
- # the _class_ method ::multiton_id.
83
+ # the uniqueness of an object. To workaround this, define the _class_
84
+ # method ::multiton_id.
85
85
  #
86
86
  # def Klass.multiton_id(*args, &block)
87
87
  # # ...
@@ -98,13 +98,13 @@
98
98
 
99
99
  module Multiton
100
100
 
101
- # pools of objects cached on class type
101
+ # Pools of objects cached on class type.
102
102
  POOLS = {}
103
103
 
104
- # method which can be defined by a class to determine object uniqueness
104
+ # Method which can be defined by a class to determine object uniqueness.
105
105
  MULTITON_ID_HOOK = :multiton_id
106
106
 
107
- # method which can be defined by a class to create multiton objects
107
+ # Method which can be defined by a class to create multiton objects.
108
108
  MULTITON_NEW_HOOK = :multiton_new
109
109
 
110
110
  def self.append_features( klass )
@@ -14,6 +14,12 @@
14
14
  #
15
15
  # Console::ProgressBar is a terminal-based progress bar library.
16
16
  #
17
+ # == Usage
18
+ #
19
+ # pbar = ConsoleProgressBar.new( "Demo", 100 )
20
+ # 100.times { pbar.inc }
21
+ # pbar.finish
22
+ #
17
23
  # == Author(s)
18
24
  #
19
25
  # * Satoru Takabayashi
@@ -24,7 +30,7 @@ module Console ; end
24
30
 
25
31
  class Console::ProgressBar
26
32
 
27
- def initialize (title, total, out = STDERR)
33
+ def initialize(title, total, out = STDERR)
28
34
  @title = title
29
35
  @total = total
30
36
  @out = out
@@ -0,0 +1,104 @@
1
+ #--
2
+ # XmlBuilder
3
+ # Copyright (c) 2006 Thomas Sawyer
4
+ #
5
+ # Ruby License
6
+ #
7
+ #++
8
+
9
+ require 'rexml/document'
10
+ require 'facets/more/builderobject'
11
+
12
+ # :title: REXMLBuilder
13
+ #
14
+ # Build XML Documents programatically with Ruby and REXML
15
+ # via the Builder Pattern --made possible by Ruby's blocks.
16
+ #
17
+ # XmlBuilder uses REXML to contruct XML documents, helping to ensure
18
+ # XML specification conforamcy.
19
+ #
20
+ # == Usage
21
+ #
22
+ # x = REXMLBuilder.new
23
+ #
24
+ # favs = [ 'cake', 'jelly', 'salt' ]
25
+ #
26
+ # x.table( :width=>'100%' ) {
27
+ # x.tr {
28
+ # favs.each { |v| x.td v }
29
+ # }
30
+ # }
31
+ # }
32
+ #
33
+ # You can also setup the XmlBuilder to assume an implicit self,
34
+ # so the explict reciever is not needed.
35
+ #
36
+ # x = REXMLBuilder.new( :implicit )
37
+ #
38
+ # x.table( :width=>'100%' ) {
39
+ # tr {
40
+ # td "1" ; td "2" ; td "3"
41
+ # }
42
+ # }
43
+ # }
44
+ #
45
+ # Implict building is more elegant in form, but it is not as
46
+ # functional because it makes it more difficult to refer to
47
+ # external values, ie. if 'favs' were used as in the previous
48
+ # example, it would be interpreted as another tag entry, not
49
+ # the array.
50
+ #
51
+
52
+ class REXMLBuilder < BuilderObject
53
+
54
+ builder_include BuilderObject::REXML
55
+
56
+ # Output XML document.
57
+
58
+ def to_s( indent=nil )
59
+ o = ""
60
+ @target.write( o, indent || @options[:indent] || 0 )
61
+ o
62
+ end
63
+
64
+ # Reroute to output.
65
+
66
+ def method_missing( tag, *args, &block )
67
+ tag = tag.to_s
68
+ if tag[-1,1] == '?'
69
+ raise ArgumentError if block_given?
70
+ out.instruct( tag.chomp('?'), *args )
71
+ elsif tag[-1,1] == '!'
72
+ out.declare( tag.chomp('!'), *args )
73
+ else
74
+ out.element( tag, *args )
75
+ end
76
+ super
77
+ end
78
+
79
+ end
80
+
81
+
82
+
83
+ # TODO
84
+
85
+ #=begin
86
+
87
+ x = REXMLBuilder.new( :version => '1.0' )
88
+
89
+ x.html {
90
+ x.head { x.title "Test Document" }
91
+ x.body( "try me" ){
92
+ x.out.text "No more!"
93
+ x.r? "x"
94
+ x.img :src=>"smile.jp"
95
+ x.h1 "Try Me"
96
+ x.h2 "This is a test."
97
+ x.div { x.span "Try" }
98
+ x.out "<jump>one</jump>"
99
+ }
100
+ }
101
+
102
+ puts x
103
+
104
+ #=end
@@ -1,6 +1,5 @@
1
1
  #--
2
2
  # Tuple
3
- #
4
3
  # Copyright (c) 2005 Thomas Sawyer
5
4
  #
6
5
  # Ruby License
@@ -16,6 +15,10 @@
16
15
  # Revision History:
17
16
  # ==========================================================================
18
17
  #
18
+ # 2006-04-10 trans
19
+ # Made thread safe (I hope) by using Multiton; No longer subclass
20
+ # of Array; and improved generally.
21
+ #
19
22
  # 2005-11-16 trans
20
23
  # Improved comparison operators to convert non-tuple parameters
21
24
  # into Tuples.
@@ -29,16 +32,22 @@
29
32
  #
30
33
  # ==========================================================================
31
34
  #
32
- # TODO: Thead Safety/Improve multiton.
35
+ # TODO The #hash method needs a touch-up.
36
+ #
37
+ # TODO There are a few more methods yet to borrow from Array.
38
+ # Consider how #+, #-, etc. ought to work.
33
39
  #
34
40
  #++
35
41
 
42
+ require 'facets/more/multiton'
43
+
36
44
  #:title: Tuple
37
45
  #
38
- # A Tuple is essentially an Array that is Multiton and Comaparable.
39
- # A Tuple can be made using #[] as one builds an array, or
40
- # using the #new method passing in an array or a string parameters
41
- # with elements divided by any non-alphanumeric character.
46
+ # Tuple is essentially an Array, but Comaparable and Immutable.
47
+ #
48
+ # A tuple can be made using #new or #[] just as one builds an array,
49
+ # or using the #to_t method on a string or array. With a string tuple
50
+ # remembers the first non-alphanumeric character as the tuple divider.
42
51
  #
43
52
  # == Usage
44
53
  #
@@ -48,30 +57,128 @@
48
57
  # t1 < t2 #=> true
49
58
  # t1 > t2 #=> false
50
59
  #
51
- # t1 = Tuple.new('1.2.3')
52
- # t2 = Tuple.new('1-2-3')
60
+ # t1 = '1.2.3'.to_t
61
+ # t2 = '1-2-3'.to_t
62
+ #
63
+ # puts t1 #=> 1.2.3
64
+ # puts t2 #=> 1-2-3
53
65
  #
54
66
  # t1 == t2 #=> true
55
67
  #
68
+ # Keep in mind that Tuple[1,2,3] is not the same as Tuple['1','2','3'].
69
+ #
56
70
  # == Author(s)
57
71
  #
58
72
  # * Thomas Sawyer
59
73
  #
60
74
 
61
- class ::Tuple < ::Array
75
+ class ::Tuple
62
76
 
77
+ include ::Multiton
78
+ include ::Enumerable
63
79
  include ::Comparable
64
80
 
65
- def initialize(args, divider=nil)
66
- super()
67
- @divider = divider || ':'
68
- self.concat args
81
+ def self.multiton_id(arg=0, default=0, &block)
82
+ if block_given?
83
+ values = []
84
+ arg.times { |i| values << block[i] }
85
+ elseif Integer === arg
86
+ values = [ default ] * arg
87
+ else
88
+ values = arg.to_ary
89
+ end
90
+ values
91
+ end
92
+
93
+ def initialize(arg=0, default=0, &blk)
94
+ if block_given?
95
+ @values = []
96
+ arg.times { |i| @values << blk[i] }
97
+ elseif Integer === arg
98
+ @values = [ default ] * arg
99
+ else
100
+ @values = arg.to_ary
101
+ end
102
+ @default = default
103
+ @divider = '.'
104
+ end
105
+
106
+ attr_accessor :default, :divider
107
+
108
+ protected
109
+
110
+ def values() @values end
111
+
112
+ public
113
+
114
+ def inspect() to_a.inspect end
115
+
116
+ def to_t() self end
117
+ def to_tuple() self end
118
+
119
+ def to_a() Array(@values) end
120
+ def to_ary() Array(@values) end
121
+
122
+ def to_s( divider=nil )
123
+ @values.join(divider||@divider)
124
+ end
125
+
126
+ def size() @values.size end
127
+ def length() @values.size end
128
+
129
+ def empty?()
130
+ return true if @values.empty?
131
+ return true if @values == [ @default ] * @values.size
132
+ false
133
+ end
134
+
135
+ def each( &block )
136
+ @values.each( &block )
137
+ end
138
+
139
+ def each_index( &block )
140
+ @values.each_index( &block )
141
+ end
142
+
143
+ def [](i)
144
+ @values.fetch(i,@default)
145
+ end
146
+
147
+ def []=(i,v)
148
+ @values[i] = v
149
+ end
150
+
151
+ def index() @values.index end
152
+ def rindex() @values.rindex end
153
+
154
+ # Unlike Array, Tuple#<< cannot act in place
155
+ # becuase Tuple's are immutable.
156
+ def <<( obj )
157
+ self.class.new( to_a << obj )
69
158
  end
70
159
 
71
- def to_s ; join(@divider) ; end
160
+ def pop() Tuple.new( to_a.pop ) end
161
+ def push( obj ) Tuple.new( to_a.push(obj) ) end
162
+ def pull() Tuple.new( to_a.shift ) end
163
+ def pot( obj ) Tuple.new( to_a.unshift(obj) ) end
164
+ alias_method :unshift, :pot
165
+ alias_method :shift, :pull
166
+
167
+ # Returns true if two tuple references are for the
168
+ # very same tuple.
169
+ def eql?( other )
170
+ return true if object_id == other.object_id
171
+ #return true if values.eql? other.values
172
+ end
72
173
 
73
- def to_t ; self ; end
74
- def to_tuple ; self ; end
174
+ def <=>( other )
175
+ other = other.to_t
176
+ [size, other.size].max.times do |i|
177
+ c = self[i] <=> other[i]
178
+ return c if c != 0
179
+ end
180
+ 0
181
+ end
75
182
 
76
183
  # For pessimistic constraint (like '~>' in gems)
77
184
  def =~( other )
@@ -81,60 +188,93 @@ class ::Tuple < ::Array
81
188
  self >= other and self < upver
82
189
  end
83
190
 
84
- def ==( other ) ; super( other.to_t ) ; end
85
- def >( other ) ; super( other.to_t ) ; end
86
- def <( other ) ; super( other.to_t ) ; end
87
- def >=( other ) ; super( other.to_t ) ; end
88
- def <=( other ) ; super( other.to_t ) ; end
191
+ def first() @values.first end
192
+ def last() @values.last end
89
193
 
90
- # class-level -----------------------------------------------
194
+ # These are useful for using a Tuple as a version.
195
+ def major() @values.first end
196
+ def minor() @values.at(1) end
197
+ def teeny() @values.at(2) end
198
+
199
+ # Unique hash value.
200
+ def hash
201
+ # TODO This needs to take into account the default
202
+ # and maybe the divider too.
203
+ to_a.hash
204
+ end
91
205
 
92
- @tuples = {}
206
+ # class-level -----------------------------------------------
93
207
 
94
208
  class << self
95
209
 
96
- alias_method :instance, :new
210
+ def []( *args )
211
+ new( args )
212
+ end
213
+
214
+ #
97
215
 
98
- def new( arg )
99
- case arg
100
- when Array, Tuple
101
- div = nil
102
- else
103
- div = /\W/.match(arg)[0]
104
- args = arg.to_s.split(/\W/).collect { |e| e.to_i }
216
+ def cast_from_string( str ) # :yield:
217
+ args = str.to_s.split(/\W/)
218
+ div = /\W/.match( str.to_s )[0]
219
+ if block_given?
220
+ args = args.collect{ |a| yld[a] }
105
221
  end
106
- @tuples[args] ||= instance(args, div)
222
+ t = self.new( args )
223
+ t.divider = div
224
+ t
107
225
  end
108
226
 
109
- def []( *args )
110
- @tuples[args] ||= instance(args)
227
+ def cast_from_array( arr )
228
+ self.new( arr )
111
229
  end
112
230
 
113
- # Parses a constraint returning the operation, and the
114
- # tuple to compare against.
115
- def decipher_constraint( constraint )
116
- if md = %r{^(=~|~>|<=|>=|==|=|<|>)(.*)$}.match( constraint.strip )
117
- opr = md[1]
118
- opr = '=~' if opr == '~>'
119
- opr = '==' if opr == '='
120
- val = instance(md[2])
231
+ # Parses a constraint returning the operation as a lambda.
232
+
233
+ def parse_constraint( constraint )
234
+ constraint = constraint.strip
235
+ re = %r{^(=~|~>|<=|>=|==|=|<|>)?(\d+(:?[-.]\d+)*)$}
236
+ if md = re.match( constraint )
237
+ if op = md[1]
238
+ op = '=~' if op == '~>'
239
+ op = '==' if op == '='
240
+ val = new( md[2] )
241
+ else
242
+ op = '=='
243
+ val = new( constraint )
244
+ end
121
245
  else
122
- opr = '=='
123
- val = instance(constraint.strip)
246
+ raise ArgumentError, "invalid constraint"
124
247
  end
125
- return opr, val
248
+ return op, val
249
+ end
250
+
251
+ def constraint_to_lambda( constraint )
252
+ op, val = *parse_constraint( constraint )
253
+ lambda { |t| t.send(op, val) }
126
254
  end
127
255
 
128
- end #class << self
256
+ end
129
257
 
130
258
  end
131
259
 
260
+
132
261
  # Conveniently turn a string into a tuple.
133
262
 
134
263
  class ::String
135
264
 
265
+ def to_t( &yld )
266
+ Tuple.cast_from_string( self, &yld )
267
+ end
268
+
269
+ end
270
+
271
+
272
+ # Convert and array into a tuple.
273
+
274
+ class ::Array
275
+
136
276
  def to_t
137
- ::Tuple.new(self)
277
+ Tuple.cast_from_array( self )
138
278
  end
139
279
 
140
280
  end
@@ -148,20 +288,44 @@ end
148
288
  # |_|\___||___/\__|
149
289
  #
150
290
 
151
- =begin test
291
+ =begin testing
152
292
 
153
293
  require 'test/unit'
154
294
 
155
- class TC_Tuple < Test::Unit::TestCase
295
+ class TC_Tuple < Test::Unit::TestCase
296
+
297
+ def test_01
298
+ t1 = Tuple[1,2,3]
299
+ t2 = Tuple[2,4,5]
300
+ assert( t1 < t2 )
301
+ assert( t2 > t1 )
302
+ end
303
+
304
+ def test_02
305
+ t1 = Tuple[1,2,3]
306
+ a1 = t1.to_a
307
+ assert( Array === a1 )
308
+ end
309
+
310
+ def test_03
311
+ t1 = Tuple[1,2,3]
312
+ t2 = Tuple[1,2,3]
313
+ assert( t1.object_id === t2.object_id )
314
+ end
156
315
 
157
- def setup
158
- @t1 = Tuple[1,2,3]
159
- @t2 = Tuple[2,4,5]
316
+ def test_04
317
+ t1 = Tuple[1,2,3]
318
+ t1 = t1 << 4
319
+ assert( Tuple === t1 )
320
+ t2 = Tuple[1,2,3,4]
321
+ assert( t1.object_id == t2.object_id )
160
322
  end
161
323
 
162
- def test_compare
163
- assert( @t1 < @t2 )
164
- assert( @t2 > @t1 )
324
+ def test_05
325
+ t1 = "1.2.3".to_t
326
+ assert( Tuple === t1 )
327
+ t2 = Tuple['1','2','3']
328
+ assert( t1.object_id == t2.object_id )
165
329
  end
166
330
 
167
331
  end