facets 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (321) hide show
  1. data/HISTORY.rdoc +331 -35
  2. data/MANIFEST +685 -826
  3. data/{doc/guide/notes.rd → NOTES} +0 -0
  4. data/README.rdoc +73 -25
  5. data/Rakefile +245 -2
  6. data/TODO +5 -0
  7. data/demo/hook.rd +47 -0
  8. data/demo/scenario_require.rd +9 -0
  9. data/doc/README.more +24 -6
  10. data/doc/manual/about.rb +47 -0
  11. data/doc/manual/annotations.rdoc +60 -0
  12. data/doc/manual/associations.rdoc +55 -0
  13. data/doc/manual/blockups.rdoc +101 -0
  14. data/doc/manual/capsule.rdoc +34 -0
  15. data/doc/manual/command.rdoc +177 -0
  16. data/doc/manual/core.rdoc +37 -0
  17. data/doc/manual/faq.rdoc +32 -0
  18. data/doc/manual/typecast.html +112 -0
  19. data/lib/core/facets.rb +359 -11
  20. data/lib/core/facets/array/combination.rb +3 -3
  21. data/lib/core/facets/array/index.rb +4 -1
  22. data/lib/core/facets/array/permutation.rb +2 -2
  23. data/lib/core/facets/array/product.rb +1 -1
  24. data/lib/core/facets/binding/eval.rb +1 -1
  25. data/lib/core/facets/denumerable.rb +76 -0
  26. data/lib/core/facets/duplicable.rb +34 -0
  27. data/lib/core/facets/enumerable/count.rb +10 -4
  28. data/lib/core/facets/enumerable/defer.rb +77 -0
  29. data/lib/core/facets/enumerable/each_by.rb +1 -1
  30. data/lib/core/facets/enumerable/every.rb +35 -0
  31. data/lib/{more/facets/elementwise.rb → core/facets/enumerable/ewise.rb} +0 -0
  32. data/lib/core/facets/enumerable/filter.rb +25 -0
  33. data/lib/core/facets/enumerable/group_by.rb +1 -1
  34. data/lib/core/facets/enumerable/none.rb +3 -2
  35. data/lib/core/facets/enumerable/one.rb +3 -2
  36. data/lib/core/facets/enumerable/per.rb +61 -0
  37. data/lib/core/facets/exception/raised.rb +14 -0
  38. data/lib/core/facets/integer/odd.rb +5 -1
  39. data/lib/core/facets/kernel/__dir__.rb +13 -3
  40. data/lib/core/facets/kernel/__here__.rb +14 -0
  41. data/lib/core/facets/kernel/__method__.rb +9 -3
  42. data/lib/core/facets/kernel/ask.rb +1 -0
  43. data/lib/core/facets/kernel/equate.rb +13 -0
  44. data/lib/core/facets/kernel/extension.rb +9 -0
  45. data/lib/core/facets/kernel/identical.rb +4 -0
  46. data/lib/core/facets/kernel/instance_exec.rb +2 -1
  47. data/lib/core/facets/kernel/method.rb +49 -0
  48. data/lib/core/facets/kernel/object_send.rb +2 -2
  49. data/lib/core/facets/kernel/{state.rb → object_state.rb} +23 -12
  50. data/lib/core/facets/kernel/require_all.rb +6 -1
  51. data/lib/core/facets/kernel/require_local.rb +8 -1
  52. data/lib/core/facets/kernel/require_relative.rb +52 -0
  53. data/lib/core/facets/kernel/source_location.rb +13 -0
  54. data/lib/core/facets/kernel/tap.rb +13 -6
  55. data/lib/core/facets/module/attr_setter.rb +57 -0
  56. data/lib/core/facets/module/instance_method.rb +24 -0
  57. data/lib/core/facets/module/module_load.rb +60 -44
  58. data/lib/core/facets/module/module_require.rb +1 -0
  59. data/lib/core/facets/nilclass/to_f.rb +1 -1
  60. data/lib/core/facets/objectspace/op_fetch.rb +3 -0
  61. data/lib/core/facets/proc/curry.rb +4 -3
  62. data/lib/core/facets/string/bytes.rb +10 -4
  63. data/lib/core/facets/string/camelcase.rb +6 -5
  64. data/lib/core/facets/string/chars.rb +5 -1
  65. data/lib/core/facets/string/each_char.rb +1 -1
  66. data/lib/core/facets/string/each_word.rb +1 -1
  67. data/lib/core/facets/string/lines.rb +11 -4
  68. data/lib/core/facets/string/start_with.rb +9 -2
  69. data/lib/core/facets/string/unfold.rb +27 -0
  70. data/lib/core/facets/symbol/succ.rb +3 -3
  71. data/lib/core/facets/symbol/thrown.rb +20 -0
  72. data/lib/core/facets/symbol/to_proc.rb +3 -2
  73. data/lib/core/facets/time/to_time.rb +1 -1
  74. data/lib/core/facets/to_hash.rb +41 -100
  75. data/lib/core/facets/unboundmethod/name.rb +20 -23
  76. data/lib/more/facets/ansicode.rb +1 -10
  77. data/lib/more/facets/autoarray.rb +3 -31
  78. data/lib/more/facets/basicobject.rb +73 -0
  79. data/lib/more/facets/blankslate.rb +2 -66
  80. data/lib/{lore → more}/facets/cgi.rb +0 -0
  81. data/lib/more/facets/class_extend.rb +1 -0
  82. data/lib/{lore → more}/facets/continuation.rb +0 -0
  83. data/lib/{lore → more}/facets/date.rb +3 -3
  84. data/lib/more/facets/enumargs.rb +192 -0
  85. data/lib/more/facets/enumerablepass.rb +2 -216
  86. data/lib/more/facets/enumerator.rb +62 -0
  87. data/lib/more/facets/{equatable.rb → equitable.rb} +11 -11
  88. data/lib/more/facets/expirable.rb +13 -41
  89. data/lib/{lore → more}/facets/fileutils.rb +0 -0
  90. data/lib/{lore → more}/facets/fileutils/head.rb +0 -0
  91. data/lib/{lore → more}/facets/fileutils/safe_ln.rb +0 -0
  92. data/lib/{lore → more}/facets/fileutils/slice.rb +0 -0
  93. data/lib/{lore → more}/facets/fileutils/tail.rb +0 -0
  94. data/lib/{lore → more}/facets/fileutils/wc.rb +0 -0
  95. data/lib/{lore → more}/facets/fileutils/whereis.rb +0 -0
  96. data/lib/{lore → more}/facets/fileutils/which.rb +0 -0
  97. data/lib/{lore → more}/facets/getoptlong.rb +0 -0
  98. data/lib/more/facets/hook.rb +2 -29
  99. data/lib/more/facets/inheritor.rb +2 -2
  100. data/lib/more/facets/instance_eval.rb +50 -0
  101. data/lib/more/facets/instance_function.rb +78 -0
  102. data/lib/more/facets/main.rb +20 -15
  103. data/lib/more/facets/memoize.rb +1 -113
  104. data/lib/more/facets/module/attr.rb +83 -0
  105. data/lib/more/facets/module/attr_tester.rb +44 -0
  106. data/lib/more/facets/module/attr_toggler.rb +59 -0
  107. data/lib/more/facets/module/attr_validator.rb +34 -0
  108. data/lib/more/facets/{class_extension.rb → module/class_extend.rb} +21 -13
  109. data/lib/more/facets/once.rb +59 -0
  110. data/lib/more/facets/openmodule.rb +1 -0
  111. data/lib/more/facets/orderedhash.rb +1 -33
  112. data/lib/{lore → more}/facets/ostruct.rb +0 -0
  113. data/lib/more/facets/ostructable.rb +1 -4
  114. data/lib/more/facets/partial.rb +18 -16
  115. data/lib/{lore → more}/facets/pathname.rb +0 -0
  116. data/lib/more/facets/preinitialize.rb +157 -0
  117. data/lib/{lore → more}/facets/rbconfig.rb +0 -0
  118. data/lib/more/facets/recorder.rb +1 -2
  119. data/lib/{lore → more}/facets/set.rb +0 -0
  120. data/lib/{lore → more}/facets/shellwords.rb +0 -0
  121. data/lib/{lore → more}/facets/uri.rb +0 -0
  122. data/lib/{lore → more}/facets/yaml.rb +0 -0
  123. data/lib/{lore → more}/facets/zlib.rb +0 -0
  124. data/meta/loadpath +0 -1
  125. data/meta/sitemap +4 -0
  126. data/meta/version +1 -1
  127. data/test/core/enumerable/test_count.rb +1 -1
  128. data/test/{more/test_filter.rb → core/enumerable/test_defer.rb} +24 -22
  129. data/test/{more/test_elementor.rb → core/enumerable/test_every.rb} +2 -15
  130. data/test/core/enumerable/test_ewise.rb +23 -0
  131. data/test/core/enumerable/test_per.rb +18 -0
  132. data/test/core/enumerable/test_take.rb +13 -0
  133. data/test/core/kernel/test_deepcopy.rb +1 -1
  134. data/test/{more/test_1stclassmethod.rb → core/kernel/test_method.rb} +2 -7
  135. data/test/core/kernel/test_tap.rb +1 -1
  136. data/test/core/proc/test_curry.rb +11 -0
  137. data/test/core/string/test_bytes.rb +1 -1
  138. data/test/core/string/test_camelcase.rb +23 -6
  139. data/test/core/string/test_lines.rb +1 -1
  140. data/test/core/string/test_unfold.rb +14 -0
  141. data/test/{more → core}/test_blank.rb +0 -0
  142. data/test/{more → core}/test_boolean.rb +0 -0
  143. data/test/{more → core}/test_functor.rb +0 -0
  144. data/test/{lore → more}/test_basicobject.rb +0 -0
  145. data/test/more/{test_class_extension.rb → test_class_extend.rb} +6 -6
  146. data/test/{lore → more}/test_continuation.rb +0 -0
  147. data/test/{lore → more}/test_date.rb +0 -0
  148. data/test/more/{test_enumerablepass.rb → test_enumargs.rb} +2 -4
  149. data/test/more/{test_equatable.rb → test_equitable.rb} +2 -2
  150. data/test/more/{test_instantise.rb → test_instance_function.rb} +3 -2
  151. data/test/more/test_memoize.rb +1 -1
  152. data/test/{lore → more}/test_ostruct.rb +0 -0
  153. metadata +865 -1016
  154. data/RELEASE +0 -38
  155. data/doc/README.lore +0 -51
  156. data/doc/log/basic_stats/index.html +0 -39
  157. data/doc/log/changelog.html +0 -648
  158. data/doc/log/changelog.txt +0 -217
  159. data/doc/log/stats/index.html +0 -39
  160. data/doc/log/testlog.txt +0 -278
  161. data/doc/notes/CHANGES +0 -2529
  162. data/doc/rdoc/lore/classes/Array.html +0 -176
  163. data/doc/rdoc/lore/classes/CGI.html +0 -191
  164. data/doc/rdoc/lore/classes/Config.html +0 -135
  165. data/doc/rdoc/lore/classes/Continuation.html +0 -113
  166. data/doc/rdoc/lore/classes/Date.html +0 -631
  167. data/doc/rdoc/lore/classes/DateTime.html +0 -583
  168. data/doc/rdoc/lore/classes/Enumerable.html +0 -89
  169. data/doc/rdoc/lore/classes/Enumerable/Enumerator.html +0 -147
  170. data/doc/rdoc/lore/classes/File.html +0 -128
  171. data/doc/rdoc/lore/classes/FileUtils.html +0 -434
  172. data/doc/rdoc/lore/classes/GetoptLong.html +0 -118
  173. data/doc/rdoc/lore/classes/GetoptLong/DSL.html +0 -208
  174. data/doc/rdoc/lore/classes/Kernel.html +0 -135
  175. data/doc/rdoc/lore/classes/Logger.html +0 -229
  176. data/doc/rdoc/lore/classes/Logger/Ansicolor.html +0 -277
  177. data/doc/rdoc/lore/classes/Logger/LogDevice.html +0 -121
  178. data/doc/rdoc/lore/classes/NilClass.html +0 -119
  179. data/doc/rdoc/lore/classes/OpenStruct.html +0 -432
  180. data/doc/rdoc/lore/classes/Pathname.html +0 -353
  181. data/doc/rdoc/lore/classes/Set.html +0 -117
  182. data/doc/rdoc/lore/classes/Shellwords.html +0 -111
  183. data/doc/rdoc/lore/classes/String.html +0 -140
  184. data/doc/rdoc/lore/classes/Time.html +0 -154
  185. data/doc/rdoc/lore/classes/URI.html +0 -454
  186. data/doc/rdoc/lore/classes/URI/Hash.html +0 -105
  187. data/doc/rdoc/lore/classes/URI/Kernel.html +0 -122
  188. data/doc/rdoc/lore/classes/Zlib.html +0 -188
  189. data/doc/rdoc/lore/created.rid +0 -1
  190. data/doc/rdoc/lore/files/README.html +0 -286
  191. data/doc/rdoc/lore/files/doc/README_lore.html +0 -155
  192. data/doc/rdoc/lore/files/lib/lore/facets/basicobject_rb.html +0 -118
  193. data/doc/rdoc/lore/files/lib/lore/facets/cgi_rb.html +0 -111
  194. data/doc/rdoc/lore/files/lib/lore/facets/continuation_rb.html +0 -147
  195. data/doc/rdoc/lore/files/lib/lore/facets/date_rb.html +0 -97
  196. data/doc/rdoc/lore/files/lib/lore/facets/enumerator_rb.html +0 -111
  197. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/head_rb.html +0 -96
  198. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/safe_ln_rb.html +0 -96
  199. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/slice_rb.html +0 -96
  200. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/tail_rb.html +0 -96
  201. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/wc_rb.html +0 -96
  202. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/whereis_rb.html +0 -96
  203. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/which_rb.html +0 -96
  204. data/doc/rdoc/lore/files/lib/lore/facets/fileutils_rb.html +0 -131
  205. data/doc/rdoc/lore/files/lib/lore/facets/getoptlong_rb.html +0 -135
  206. data/doc/rdoc/lore/files/lib/lore/facets/logger_rb.html +0 -142
  207. data/doc/rdoc/lore/files/lib/lore/facets/ostruct_rb.html +0 -135
  208. data/doc/rdoc/lore/files/lib/lore/facets/pathname_rb.html +0 -145
  209. data/doc/rdoc/lore/files/lib/lore/facets/rbconfig_rb.html +0 -124
  210. data/doc/rdoc/lore/files/lib/lore/facets/set_rb.html +0 -96
  211. data/doc/rdoc/lore/files/lib/lore/facets/shellwords_rb.html +0 -124
  212. data/doc/rdoc/lore/files/lib/lore/facets/uri_rb.html +0 -125
  213. data/doc/rdoc/lore/files/lib/lore/facets/yaml_rb.html +0 -146
  214. data/doc/rdoc/lore/files/lib/lore/facets/zlib_rb.html +0 -97
  215. data/doc/rdoc/lore/fr_class_index.html +0 -73
  216. data/doc/rdoc/lore/fr_file_index.html +0 -71
  217. data/doc/rdoc/lore/fr_method_index.html +0 -177
  218. data/doc/rdoc/lore/index.html +0 -26
  219. data/doc/rdoc/lore/rdoc-style.css +0 -177
  220. data/doc/release-notes/RELEASE-2.0.5 +0 -8
  221. data/doc/release-notes/RELEASE-2.1.0 +0 -9
  222. data/doc/release-notes/RELEASE-2.1.1 +0 -5
  223. data/doc/release-notes/RELEASE-2.1.2 +0 -6
  224. data/doc/release-notes/RELEASE-2.1.3 +0 -5
  225. data/doc/release-notes/RELEASE-2.2.0 +0 -14
  226. data/doc/release-notes/RELEASE-2.2.1 +0 -4
  227. data/doc/release-notes/RELEASE-2.3.0 +0 -6
  228. data/doc/release-notes/RELEASE-2.4.0 +0 -70
  229. data/doc/release-notes/RELEASE-2.4.1 +0 -8
  230. data/doc/release-notes/RELEASE-2.4.2 +0 -4
  231. data/doc/release-notes/RELEASE-2.4.3 +0 -78
  232. data/doc/release-notes/RELEASE-2.4.4 +0 -38
  233. data/doc/release-notes/RELEASE-2.4.5 +0 -37
  234. data/doc/release-notes/RELEASE-2.5.0 +0 -83
  235. data/lib/core/facets/kernel/instance.rb +0 -19
  236. data/lib/lore/facets/basicobject.rb +0 -14
  237. data/lib/lore/facets/enumerator.rb +0 -67
  238. data/lib/lore/facets/logger.rb +0 -291
  239. data/lib/more/facets/1stclassmethod.rb +0 -140
  240. data/lib/more/facets/advisable.rb +0 -162
  241. data/lib/more/facets/association.rb +0 -210
  242. data/lib/more/facets/attr.rb +0 -209
  243. data/lib/more/facets/basex.rb +0 -37
  244. data/lib/more/facets/bbcode.rb +0 -397
  245. data/lib/more/facets/bicrypt.rb +0 -265
  246. data/lib/more/facets/binreadable.rb +0 -221
  247. data/lib/more/facets/censor.rb +0 -97
  248. data/lib/more/facets/classmethods.rb +0 -199
  249. data/lib/more/facets/consoleutils.rb +0 -99
  250. data/lib/more/facets/crypt.rb +0 -166
  251. data/lib/more/facets/dependency.rb +0 -151
  252. data/lib/more/facets/downloader.rb +0 -281
  253. data/lib/more/facets/duplicable.rb +0 -43
  254. data/lib/more/facets/elementor.rb +0 -133
  255. data/lib/more/facets/filter.rb +0 -121
  256. data/lib/more/facets/heap.rb +0 -22
  257. data/lib/more/facets/infinity.rb +0 -193
  258. data/lib/more/facets/ini.rb +0 -264
  259. data/lib/more/facets/instantise.rb +0 -1
  260. data/lib/more/facets/instantize.rb +0 -95
  261. data/lib/more/facets/interval.rb +0 -282
  262. data/lib/more/facets/iteration.rb +0 -65
  263. data/lib/more/facets/linkedlist.rb +0 -222
  264. data/lib/more/facets/lrucache.rb +0 -157
  265. data/lib/more/facets/matcher.rb +0 -140
  266. data/lib/more/facets/memoizer.rb +0 -74
  267. data/lib/more/facets/minitar.rb +0 -1063
  268. data/lib/more/facets/nackclass.rb +0 -41
  269. data/lib/more/facets/net/smtp_tls.rb +0 -131
  270. data/lib/more/facets/nilstatus.rb +0 -48
  271. data/lib/more/facets/overload.rb +0 -94
  272. data/lib/more/facets/paramix.rb +0 -202
  273. data/lib/more/facets/pool.rb +0 -91
  274. data/lib/more/facets/pqueue.rb +0 -449
  275. data/lib/more/facets/pry.rb +0 -32
  276. data/lib/more/facets/reflection.rb +0 -145
  277. data/lib/more/facets/semaphore.rb +0 -92
  278. data/lib/more/facets/settings.rb +0 -248
  279. data/lib/more/facets/snapshot.rb +0 -209
  280. data/lib/more/facets/sparse_array.rb +0 -809
  281. data/lib/more/facets/string/mask.rb +0 -278
  282. data/lib/more/facets/string/obfuscate.rb +0 -65
  283. data/lib/more/facets/string/stylize.rb +0 -169
  284. data/lib/more/facets/string/words.rb +0 -167
  285. data/lib/more/facets/syncarray.rb +0 -114
  286. data/lib/more/facets/synchash.rb +0 -157
  287. data/lib/more/facets/typecast.rb +0 -261
  288. data/lib/more/facets/uninheritable.rb +0 -50
  289. data/lib/more/facets/xmlhash.rb +0 -112
  290. data/lib/more/facets/xoxo.rb +0 -259
  291. data/lib/more/facets/ziputils.rb +0 -490
  292. data/task/conflicts +0 -63
  293. data/task/coverage.rake +0 -37
  294. data/task/methods +0 -49
  295. data/task/rdoc.rake +0 -17
  296. data/task/setup.rake +0 -38
  297. data/task/test.rake +0 -145
  298. data/test/more/test_advisable.rb +0 -71
  299. data/test/more/test_association.rb +0 -38
  300. data/test/more/test_bbcode.rb +0 -21
  301. data/test/more/test_binreadable.rb +0 -50
  302. data/test/more/test_buildable.rb +0 -73
  303. data/test/more/test_classmethods.rb +0 -56
  304. data/test/more/test_crypt.rb +0 -32
  305. data/test/more/test_dependency.rb +0 -69
  306. data/test/more/test_elementwise.rb +0 -25
  307. data/test/more/test_infinity.rb +0 -40
  308. data/test/more/test_interval.rb +0 -151
  309. data/test/more/test_linkedlist.rb +0 -41
  310. data/test/more/test_lrucache.rb +0 -14
  311. data/test/more/test_overload.rb +0 -160
  312. data/test/more/test_paramix.rb +0 -170
  313. data/test/more/test_prototype.rb +0 -35
  314. data/test/more/test_snapshot.rb +0 -21
  315. data/test/more/test_sparsearray.rb +0 -279
  316. data/test/more/test_syncarray.rb +0 -15
  317. data/test/more/test_synchash.rb +0 -16
  318. data/test/more/test_typecast.rb +0 -54
  319. data/test/more/test_uninheritable.rb +0 -31
  320. data/test/more/test_xoxo.rb +0 -274
  321. data/test/test_facets.rb +0 -9
@@ -1,209 +0,0 @@
1
- class Module
2
-
3
- # Like attr_writer, but the writer method validates the
4
- # setting against the given block.
5
- #
6
- # CREDIT: ?
7
-
8
- def attr_validator(*symbols, &validator)
9
- made = []
10
- symbols.each do |symbol|
11
- define_method "#{symbol}=" do |val|
12
- unless validator.call(val)
13
- raise ArgumentError, "Invalid value provided for #{symbol}"
14
- end
15
- instance_variable_set("@#{symbol}", val)
16
- end
17
- made << "#{symbol}=".to_sym
18
- end
19
- made
20
- end
21
-
22
- # Create aliases for validators.
23
-
24
- def alias_validator(*args)
25
- orig = args.last
26
- args = args - [orig]
27
- args.each do |name|
28
- #alias_method(name, orig)
29
- alias_method("#{name}=", "#{orig}=")
30
- end
31
- end
32
-
33
- # TODO Perhaps need to make a check against overriding annotated version.
34
-
35
- # Create an attribute method for both getting
36
- # and setting an instance variable.
37
- #
38
- # attr_setter :a
39
- #
40
- # _is equivalent to_
41
- #
42
- # def a(*args)
43
- # if args.size > 0
44
- # @a = args[0]
45
- # self
46
- # else
47
- # @a
48
- # end
49
- # end
50
- #
51
- # CREDIT: Trans
52
-
53
- def attr_setter(*args)
54
- code, made = '', []
55
- args.each do |a|
56
- code << %{
57
- def #{a}(*args)
58
- args.size > 0 ? ( @#{a}=args[0] ; self ) : @#{a}
59
- end
60
- }
61
- made << "#{a}".to_sym
62
- end
63
- module_eval code
64
- made
65
- end
66
-
67
- # Alias an accessor. This create an alias for
68
- # both a reader and a writer.
69
- #
70
- # class X
71
- # attr_accessor :a
72
- # alias_accessor :b, :a
73
- # end
74
- #
75
- # x = X.new
76
- # x.b = 1
77
- # x.a #=> 1
78
- #
79
- # CREDIT: Trans
80
-
81
- def alias_setter(*args)
82
- args = args - [orig]
83
- args.each do |name|
84
- alias_method(name, orig)
85
- end
86
- end
87
-
88
- # Create a toggle attribute. This creates two methods for
89
- # each given name. One is a form of tester and the other
90
- # is used to toggle the value.
91
- #
92
- # attr_accessor! :a
93
- #
94
- # is equivalent to
95
- #
96
- # def a?
97
- # @a
98
- # end
99
- #
100
- # def a!(value=true)
101
- # @a = value
102
- # self
103
- # end
104
- #
105
- # CREDIT: Trans
106
-
107
- def attr_accessor!(*args)
108
- attr_reader!(*args) + attr_writer!(*args)
109
- end
110
- alias_method :attr_switcher, :attr_accessor!
111
- alias_method :attr_toggler, :attr_accessor!
112
-
113
- # Create aliases for flag accessors.
114
- #
115
- # CREDIT: Trans
116
-
117
- def alias_accessor!(*args)
118
- orig = args.last
119
- args = args - [orig]
120
- args.each do |name|
121
- alias_method("#{name}?", "#{orig}?")
122
- alias_method("#{name}!", "#{orig}!")
123
- end
124
- end
125
- alias_method :alias_switcher, :alias_accessor!
126
- alias_method :alias_toggler, :alias_accessor!
127
-
128
- # Create an tester attribute. This creates a single method
129
- # used to test the attribute for truth.
130
- #
131
- # attr_reader! :a
132
- #
133
- # is equivalent to
134
- #
135
- # def a?
136
- # @a ? true : @a
137
- # end
138
- #
139
- def attr_reader!(*args)
140
- code, made = '', []
141
- args.each do |a|
142
- code << %{
143
- def #{a}?(truth=nil)
144
- @#{a} ? truth || @#{a} : @#{a}
145
- end
146
- }
147
- made << "#{a}?".to_sym
148
- end
149
- module_eval code
150
- made
151
- end
152
- alias_method :attr_reader?, :attr_reader!
153
- alias_method :attr_tester, :attr_reader!
154
-
155
- # Create aliases for flag reader.
156
- #
157
- # CREDIT: Trans
158
-
159
- def alias_reader!(*args)
160
- orig = args.last
161
- args = args - [orig]
162
- args.each do |name|
163
- alias_method("#{name}?", "#{orig}?")
164
- end
165
- end
166
- alias_method :alias_reader?, :alias_reader!
167
- alias_method :alias_tester, :alias_reader!
168
-
169
- # Create a flaggable attribute. This creates a single methods
170
- # used to set an attribute to "true".
171
- #
172
- # attr_writer! :a
173
- #
174
- # is equivalent to
175
- #
176
- # def a!(value=true)
177
- # @a = value
178
- # self
179
- # end
180
- #
181
- def attr_writer!(*args)
182
- code, made = '', []
183
- args.each do |a|
184
- code << %{
185
- def #{a}!(value=true)
186
- @#{a} = value
187
- self
188
- end
189
- }
190
- made << "#{a}!".to_sym
191
- end
192
- module_eval code
193
- made
194
- end
195
-
196
- # Create aliases for flag writer.
197
- #
198
- # CREDIT: Trans
199
-
200
- def alias_writer!(*args)
201
- orig = args.last
202
- args = args - [orig]
203
- args.each do |name|
204
- alias_method("#{name}!", "#{orig}!")
205
- end
206
- end
207
-
208
- end
209
-
@@ -1,37 +0,0 @@
1
- class BaseX
2
-
3
- BASE62 = ["0".."9", "a".."z", "A".."Z"].map { |r| r.to_a }.flatten
4
-
5
- attr :chars, :base, :values
6
-
7
- def initialize(chars=BASE62)
8
- @chars = chars
9
- @base = @chars.size
10
- @values = Hash[*(0...@base).map { |i| [ @chars[i], i ] }.flatten]
11
- end
12
-
13
- def encode(byte_string)
14
- convert_base(byte_string.unpack("C*"), 256, @base).map { |d|
15
- @chars[d]
16
- }.join('')
17
- end
18
-
19
- def decode(encoded)
20
- convert_base(encoded.split('').map { |c|
21
- @values[c]
22
- }, @base, 256).pack("C*")
23
- end
24
-
25
- def convert_base(digits, from_base, to_base)
26
- bignum = 0
27
- digits.each { |digit| bignum = bignum * from_base + digit }
28
- converted = []
29
- until bignum.zero?
30
- bignum, digit = bignum.divmod to_base
31
- converted.push digit
32
- end
33
- converted.reverse
34
- end
35
-
36
- end
37
-
@@ -1,397 +0,0 @@
1
- # = BBCode
2
- #
3
- # = Synopsis
4
- #
5
- # The BBCode module helps ease the separation of core and frontend with the
6
- # core (or submodules) being still able to say, what colors shall be used
7
- # in it's responses. This is achieved by encoding formatting information
8
- # using the BBCode tokens. This enables you to "pipe" layout information
9
- # such as colors, style, fonttype, size and alignment through the core to
10
- # the frontend.
11
- #
12
- # Additionally it converts markups/codes between ANSI, HTML and BBCode
13
- # almost freely ;)
14
- #
15
- # == Usage
16
- #
17
- # # Converting a bbcode string to ANSI and XHTML
18
- #
19
- # str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
20
- # print( BBCode.bbcode_to_ansi(str) )
21
- # print( BBCode.bbcode_to_html(str) )
22
- #
23
- # == Authors
24
- #
25
- # * Thomas-Ivo Heinen
26
- #
27
- # == Copying
28
- #
29
- # Copyright (c) 2002 Thomas-Ivo Heinen
30
- #
31
- # Ruby License
32
- #
33
- # This module is free software. You may use, modify, and/or redistribute this
34
- # software under the same terms as Ruby.
35
- #
36
- # This program is distributed in the hope that it will be useful, but WITHOUT
37
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
38
- # FOR A PARTICULAR PURPOSE.
39
-
40
- # = BBCode
41
- #
42
- # The BBCode module helps ease the separation of core and frontend with the
43
- # core (or submodules) being still able to say, what colors shall be used
44
- # in it's responses. This is achieved by encoding formatting information
45
- # using the BBCode tokens. This enables you to "pipe" layout information
46
- # such as colors, style, fonttype, size and alignment through the core to
47
- # the frontend.
48
- #
49
- # Additionally it converts markups/codes between ANSI, HTML and BBCode
50
- # almost freely ;)
51
- #
52
- # == Usage
53
- #
54
- # # Converting a bbcode string to ANSI and XHTML
55
- #
56
- # str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
57
- # print( BBCode.bbcode_to_ansi(str) )
58
- # print( BBCode.bbcode_to_html(str) )
59
- #
60
- module BBCode
61
-
62
- ## ANSIname => ANSIcode LUT
63
- ANSINAME2CODE= { "reset" => "\e[0m", "bold" => "\e[1m",
64
- "underline" => "\e[4m", "blink" => "\e[5m",
65
- "reverse" => "\e[7m", "invisible" => "\e[8m",
66
- "black" => "\e[0;30m", "darkgrey" => "\e[1;30m",
67
- "red" => "\e[0;31m", "lightred" => "\e[1;31m",
68
- "green" => "\e[0;32m", "lightgreen" => "\e[1;32m",
69
- "brown" => "\e[0;33m", "yellow" => "\e[1;33m",
70
- "blue" => "\e[0;34m", "lightblue" => "\e[1;34m",
71
- "purple" => "\e[0;35m", "magenta" => "\e[1;35m",
72
- "cyan" => "\e[1;36m", "lightcyan" => "\e[1;36m",
73
- "grey" => "\e[0;37m", "white" => "\e[1;37m",
74
- "bgblack" => "\e[40m", "bgred" => "\e[41m",
75
- "bggreen" => "\e[42m", "bgyellow" => "\e[43m",
76
- "bgblue" => "\e[44m", "bgmagenta" => "\e[45m",
77
- "bgcyan" => "\e[46m", "bgwhite" => "\e[47m"
78
- }
79
-
80
- ## BBColor => ANSIname LUT
81
- BBCOLOR2ANSI = { "skyblue" => "blue", "royalblue" => "blue",
82
- "blue" => "blue", "darkblue" => "blue",
83
- "orange" => "red", "orangered" => "red",
84
- "crimson" => "red", "red" => "lightred",
85
- "firebrick" => "red", "darkred" => "red",
86
- "green" => "green", "limegreen" => "green",
87
- "seagreen" => "green", "darkgreen" => "green",
88
- "deeppink" => "magenta", "tomato" => "red",
89
- "coral" => "cyan", "purple" => "purple",
90
- "indigo" => "blue", "burlywood" => "red",
91
- "sandybrown"=> "red", "sierra" => "sierra",
92
- "chocolate" => "brown", "teal" => "teal",
93
- "silver" => "white",
94
- "black" => "black", "yellow" => "yellow",
95
- "magenta" => "magenta", "cyan" => "cyan",
96
- "white" => "white"
97
- }
98
-
99
- ## ANSInames => BBCode LUT
100
- ANSINAME2BBCODE = { "bold" => "B", "underline" => "U", "reverse" => "I",
101
-
102
- "red" => "COLOR=red", "blue" => "COLOR=blue",
103
- "green" => "COLOR=green", "cyan" => "COLOR=cyan",
104
- "magenta"=> "COLOR=deeppink", "purple" => "COLOR=purple",
105
- "black" => "COLOR=black", "white" => "COLOR=white",
106
- "yellow" => "COLOR=yellow", "brown" => "COLOR=chocolate"
107
- }
108
-
109
- ## Needed for alignments
110
- @@width = 80
111
-
112
-
113
- # ---------------------------
114
-
115
- # Returns the ANSI sequence for given color, if existant
116
- def BBCode.ansi(colorname)
117
- colorname.strip!
118
- return ANSINAME2CODE[ colorname.downcase ]
119
- end
120
-
121
- # --- strip_bbcode( string )
122
- # Will strip any BBCode tags from the given string.
123
- def BBCode.strip_bbcode(string)
124
- string.strip!
125
- return string.gsub(/\[[A-Za-z0-9\/=]+\]/, "")
126
- end
127
-
128
- # Returns the string with all ansi escape sequences converted to BBCodes
129
- def BBCode.ansi_to_bbcode(string)
130
- return "" if string.nil? || string.to_s.strip.empty?
131
- result = ""
132
- tagstack = []
133
-
134
- ## Iterate over input lines
135
- string.split("\n").each do |line|
136
- ansi = line.scan(/\e\[[0-9;]+m/)
137
- continue if ansi.nil? || ansi.empty?
138
-
139
- ## Iterate over found ansi sequences
140
- ansi.each do |seq|
141
- ansiname = ANSINAME2CODE.invert["#{seq}"]
142
-
143
- ## Pop last tag and form closing tag
144
- if ansiname == "reset"
145
- lasttag = tagstack.pop
146
- bbname = "/" + String.new( lasttag.split("=")[0] )
147
-
148
- ## Get corresponding BBCode tag + Push to stack
149
- else
150
- bbname = ANSINAME2BBCODE[ansiname]
151
- tagstack.push(bbname)
152
- end
153
-
154
- ## Replace ansi sequence by BBCode tag
155
- replace = sprintf("[%s]", bbname)
156
- line.sub!("#{Regexp.quote(seq)}", replace)
157
- end
158
-
159
- ## Append converted line
160
- result << sprintf("%s\n", line)
161
- end
162
-
163
-
164
- ## Some tags are unclosed
165
- while !tagstack.empty?
166
- result << sprintf("[/%s]", String.new(tagstack.pop.split("=")[0]) )
167
- end
168
-
169
- return result
170
- end
171
-
172
- # Converts a BBCode string to one with ANSI sequences.
173
- # Returns the string with all formatting instructions in BBCodes converted
174
- # to ANSI code sequences / aligned with spaces to specified width.
175
- def BBCode.bbcode_to_ansi(string, usecolors = true)
176
- return "" if string.nil? || string.to_s.strip.empty?
177
- result = ""
178
-
179
- return BBCode.strip_bbcode(string) if !usecolors
180
-
181
- ## Iterate over lines
182
- string.split("\n").each do |line|
183
-
184
- ## TODO: stacking? other styles!
185
- ANSINAME2BBCODE.each do |key,val|
186
- line.gsub!(/\[#{val}\]/, ANSINAME2CODE[key])
187
- line.gsub!(/\[\/#{val}\]/, ANSINAME2CODE["reset"])
188
- end
189
-
190
- ## Fonttypes and sizes not available
191
- line.gsub!(/\[SIZE=\d\]/, "")
192
- line.gsub!(/\[\/SIZE\]/, "")
193
- line.gsub!(/\[FONT=[^\]]*\]/, "")
194
- line.gsub!(/\[\/FONT\]/, "")
195
-
196
- ## Color-mapping
197
- colors = line.scan(/\[COLOR=(.*?)\]/i)
198
- colors = colors.collect{|s| s[0].to_s} if !colors.nil?
199
- colors.each do |col|
200
- name = BBCOLOR2ANSI[col.downcase]
201
- name = BBCOLOR2ANSI["white"] if name.nil?
202
- code = ANSINAME2CODE[name]
203
-
204
- line.gsub!(/\[COLOR=#{col}\]/i, code)
205
- end
206
- line.gsub!(/\[\/COLOR\]/, ANSINAME2CODE["reset"])
207
-
208
- ## TODO: Alignment
209
- ## TODO: IMGs
210
- ## TODO: EMAILs
211
- ## TODO: URLs
212
- ## TODO: QUOTEs
213
- ## TODO: LISTs
214
-
215
- result << sprintf("%s\n", line)
216
- end
217
-
218
- return result
219
- end
220
-
221
- # Converts a HTML string into one with BBCode markup (TODO)
222
- # Returns the (X)HTML markup string as BBCode
223
- def BBCode.html_to_bbcode(string)
224
- return "" if string.nil? || string.to_s.strip.empty?
225
- result = ""
226
-
227
- ## Iterate over lines
228
- string.split(/<br *\/?>/i).each do |line|
229
- styles = { "strong" => "b", "b" => "b",
230
- "em" => "i", "i" => "i",
231
- "u" => "u" }
232
-
233
- ## preserve B, I, U
234
- styles.each do |html,code|
235
- line.gsub!(/<#{html}>/i, "[#{code.upcase}]")
236
- line.gsub!(/<\/#{html}>/i, "[/#{code.upcase}]")
237
- end
238
-
239
- ## TODO: COLORs
240
- ## TODO: SIZEs
241
- ## TODO: FONTs
242
-
243
- ## EMAIL
244
- line.gsub!(/<a +href *= *\"mailto:(.*?)\".*?>.*?<\/a>/i, "[EMAIL]\\1[/EMAIL]")
245
-
246
- ## URL
247
- line.gsub!(/<a +href *= *\"((?:https?|ftp):\/\/.*?)\".*?>(.*?)<\/a>/i, "[URL=\\1]\\2[/URL]")
248
-
249
- ## Other refs + closing tags => throw away
250
- line.gsub!(/<a +href *= *\".*?\".*?>/i, "")
251
- line.gsub!(/<\/a>/i, "")
252
-
253
- ## IMG
254
- #line.gsub!(/<img +src *= *\"(.*?)\".*?\/?>/i, "[IMG=\\1]")
255
- line.gsub!(/<img +src *= *\"(.*?)\".*?\/?>/i, "[IMG]\\1[/IMG]")
256
-
257
- ## CENTER (right/left??)
258
- line.gsub!(/<center>/i, "[ALIGN=center]")
259
- line.gsub!(/<\/center>/i, "[/ALIGN]")
260
-
261
- ## QUOTE
262
- line.gsub!(/<(?:xmp|pre)>/i, "[QUOTE]")
263
- line.gsub!(/<\/(?:xmp|pre)>/i, "[/QUOTE]")
264
-
265
- ## LIST
266
- line.gsub!(/<ul>/i, "\n[LIST]\n")
267
- line.gsub!(/<\/ul>/i, "\n[/LIST]\n")
268
- line.gsub!(/<li *\/?> */i, "\n[*] ")
269
-
270
- ## Unkown tags => throw away
271
- line.gsub!(/<.*? *\/?>/, "")
272
-
273
- result << sprintf("%s<br />\n", line)
274
- end
275
-
276
- return result.gsub!(/<br *\/?>/i, "\n")
277
- end
278
-
279
- # Converts a BBCode string to one with HTML markup.
280
- # Returns the string with all formatting instructions in
281
- # BBCodes converted to XHTML markups.
282
- def BBCode.bbcode_to_html(string)
283
- return "" if string.nil? || string.to_s.strip.empty?
284
- result = ""
285
- quote = 0
286
-
287
- ## Iterate over lines
288
- string.split("\n").each do |line|
289
- styles = { "b" => "strong", "i" => "em", "u" => "u" }
290
-
291
- ## preserve B, I, U
292
- styles.each do |code,html|
293
- line.gsub!(/\[#{code}\]/i, "<#{html}>")
294
- line.gsub!(/\[\/#{code}\]/i, "</#{html}>")
295
- end
296
-
297
- ## COLOR => font color=... (TODO: should be numeric!)
298
- line.gsub!(/\[COLOR=(.*?)\]/i, "<font color=\"\\1\">")
299
- line.gsub!(/\[\/COLOR\]/i, "</font>")
300
-
301
- ## SIZE => font size=...
302
- line.gsub!(/\[SIZE=(.*?)\]/i, "<font size=\"\\1\">")
303
- line.gsub!(/\[\/SIZE\]/i, "</font>")
304
-
305
- ## URL
306
- line.gsub!(/\[URL\]([^\[]+?)\[\/URL\]/i, "<a href=\"\\1\">\\1</a>")
307
- line.gsub!(/\[URL=(.*?)\](.+?)\[\/URL\]/i, "<a href=\"\\1\">\\2</a>")
308
-
309
- ## IMG
310
- line.gsub!(/\[IMG=(.*?)\]/i, "<img src=\"\\1\" />")
311
-
312
- ## ALIGN=center (TODO: right, left)
313
- line.gsub!(/\[ALIGN=center\]/i, "<center>")
314
- line.gsub!(/\[ALIGN=right\]/i, "<center>")
315
- line.gsub!(/\[ALIGN=left\]/i, "<center>")
316
- line.gsub!(/\[\/ALIGN\]/i, "</center>")
317
-
318
- ## QUOTE
319
- quote+=1 if line =~ /\[QUOTE\]/i
320
- quote-=1 if (line =~ /\[\/QUOTE\]/i) && (quote > -1)
321
- line.gsub!(/\[QUOTE\]/i, "<pre>\n")
322
- line.gsub!(/\[\/QUOTE\]/i, "</pre>\n")
323
- line.gsub!(/^/, "&#62;"*quote) if quote > 0
324
-
325
- ## EMAIL
326
- line.gsub!(/\[EMAIL\](.*?)\[\/EMAIL\]/i, "<a href=\"mailto:\\1\">\\1</a>")
327
-
328
- ## LIST (TODO: LIST=1, LIST=A)
329
- line.gsub!(/\[LIST(?:=(.*?))?\]/i, "\n<ul>\n")
330
- line.gsub!(/\[\/LIST\]/i, "\n</ul>\n")
331
- line.gsub!(/\[\*\]/i, "\n<li />")
332
-
333
- ## FONT => font ??????
334
- ## ?BLUR?, FADE?
335
-
336
- result << sprintf("%s<br />\n", line)
337
- end
338
-
339
- return result
340
- end
341
-
342
-
343
- # -- Transitive methods ---------------
344
-
345
- # Converts a ANSI string to one with HTML markup.
346
- # Returns the string with ANSI code sequences converted to XHTML markup.
347
- def BBCode.ansi_to_html(string)
348
- bbcoded = BBCode.ansi_to_bbcode(string )
349
- htmled = BBCode.bbcode_to_html(bbcoded)
350
-
351
- return htmled
352
- end
353
-
354
- # Returns the (X)HTML markup code as ANSI sequences
355
- def BBCode.html_to_ansi(string)
356
- bbcoded = BBCode.html_to_bbcode(string )
357
- ansied = BBCode.bbcode_to_ansi(bbcoded)
358
-
359
- return ansied
360
- end
361
-
362
- end #module BBCode
363
-
364
-
365
-
366
- # _____ _
367
- # |_ _|__ ___| |_
368
- # | |/ _ \/ __| __|
369
- # | | __/\__ \ |_
370
- # |_|\___||___/\__|
371
- #
372
-
373
- =begin testing
374
-
375
- require 'test/unit'
376
-
377
- class TC_BBCode < Test::Unit::TestCase
378
-
379
- def test_to_ansi
380
- str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
381
- out = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
382
- assert_equal( out, BBCode.bbcode_to_ansi(str) )
383
- end
384
-
385
- def test_to_html
386
- str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
387
- out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
388
- assert_equal( out, BBCode.bbcode_to_html(str) )
389
- end
390
-
391
- end
392
-
393
- =end
394
-
395
-
396
- # CREDIT Thomas-Ivo Heinen
397
-