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,264 +0,0 @@
1
- #
2
- # ini.rb - read and write ini files
3
- #
4
- # Copyright (C) 2007 Jeena Paradies
5
- # License: GPL
6
- # Author: Jeena Paradies (info@jeenaparadies.net)
7
- #
8
- # == Overview
9
- #
10
- # This file provides a read-wite handling for ini files.
11
- # The data of a ini file is represented by a object which
12
- # is populated with strings.
13
-
14
- class Ini
15
-
16
- # Class with methods to read from and write into ini files.
17
- #
18
- # A ini file is a text file in a specific format,
19
- # it may include several fields which are sparated by
20
- # field headlines which are enclosured by "[]".
21
- # Each field may include several key-value pairs.
22
- #
23
- # Each key-value pair is represented by one line and
24
- # the value is sparated from the key by a "=".
25
- #
26
- # == Examples
27
- #
28
- # === Example ini file
29
- #
30
- # # this is the first comment which will be saved in the comment attribute
31
- # mail=info@example.com
32
- # domain=example.com # this is a comment which will not be saved
33
- # [database]
34
- # db=example
35
- # user=john
36
- # passwd=very-secure
37
- # host=localhost
38
- # # this is another comment
39
- # [filepaths]
40
- # tmp=/tmp/example
41
- # lib=/home/john/projects/example/lib
42
- # htdocs=/home/john/projects/example/htdocs
43
- # [ texts ]
44
- # wellcome=Wellcome on my new website!
45
- # Website description = This is only a example. # and another comment
46
- #
47
- # === Example object
48
- #
49
- # A Ini#comment stores:
50
- # "this is the first comment which will be saved in the comment attribute"
51
- #
52
- # A Ini object stores:
53
- #
54
- # {
55
- # "mail" => "info@example.com",
56
- # "domain" => "example.com",
57
- # "database" => {
58
- # "db" => "example",
59
- # "user" => "john",
60
- # "passwd" => "very-secure",
61
- # "host" => "localhost"
62
- # },
63
- # "filepaths" => {
64
- # "tmp" => "/tmp/example",
65
- # "lib" => "/home/john/projects/example/lib",
66
- # "htdocs" => "/home/john/projects/example/htdocs"
67
- # }
68
- # "texts" => {
69
- # "wellcome" => "Wellcome on my new website!",
70
- # "Website description" => "This is only a example."
71
- # }
72
- # }
73
- #
74
- # As you can see this module gets rid of all comments, linebreaks
75
- # and unnecessary spaces at the beginning and the end of each
76
- # field headline, key or value.
77
- #
78
- # === Using the object
79
- #
80
- # Using the object is stright forward:
81
- #
82
- # ini = Ini.new("path/settings.ini")
83
- # ini["mail"] = "info@example.com"
84
- # ini["filepaths"] = { "tmp" => "/tmp/example" }
85
- # ini.comment = "This is\na comment"
86
- # puts ini["filepaths"]["tmp"]
87
- # # => /tmp/example
88
- # ini.write()
89
- #
90
-
91
- #
92
- # :inihash is a hash which holds all ini data
93
- # :comment is a string which holds the comments on the top of the file
94
- #
95
- attr_accessor :inihash, :comment
96
-
97
- #
98
- # Creating a new Ini object
99
- #
100
- # +path+ is a path to the ini file
101
- # +load+ if nil restores the data if possible
102
- # if true restores the data, if not possible raises an error
103
- # if false does not resotre the data
104
- #
105
- def initialize(path, load=nil)
106
- @path = path
107
- @inihash = {}
108
-
109
- if load or ( load.nil? and FileTest.readable_real? @path )
110
- restore()
111
- end
112
- end
113
-
114
- #
115
- # Retrive the ini data for the key +key+
116
- #
117
- def [](key)
118
- @inihash[key]
119
- end
120
-
121
- #
122
- # Set the ini data for the key +key+
123
- #
124
- def []=(key, value)
125
- raise TypeError, "String expected" unless key.is_a? String
126
- raise TypeError, "String or Hash expected" unless value.is_a? String or value.is_a? Hash
127
-
128
- @inihash[key] = value
129
- end
130
-
131
- #
132
- # Restores the data from file into the object
133
- #
134
- def restore()
135
- @inihash = Ini.read_from_file(@path)
136
- @comment = Ini.read_comment_from_file(@path)
137
- end
138
-
139
- #
140
- # Store data from the object in the file
141
- #
142
- def update()
143
- Ini.write_to_file(@path, @inihash, @comment)
144
- end
145
-
146
- #
147
- # Reading data from file
148
- #
149
- # +path+ is a path to the ini file
150
- #
151
- # returns a hash which represents the data from the file
152
- #
153
- def Ini.read_from_file(path)
154
-
155
- inihash = {}
156
- headline = nil
157
-
158
- IO.foreach(path) do |line|
159
-
160
- line = line.strip.split(/#/)[0]
161
-
162
- # read it only if the line doesn't begin with a "=" and is long enough
163
- unless line.length < 2 and line[0,1] == "="
164
-
165
- # it's a headline if the line begins with a "[" and ends with a "]"
166
- if line[0,1] == "[" and line[line.length - 1, line.length] == "]"
167
-
168
- # get rid of the [] and unnecessary spaces
169
- headline = line[1, line.length - 2 ].strip
170
- inihash[headline] = {}
171
- else
172
-
173
- key, value = line.split(/=/, 2)
174
-
175
- key = key.strip unless key.nil?
176
- value = value.strip unless value.nil?
177
-
178
- unless headline.nil?
179
- inihash[headline][key] = value
180
- else
181
- inihash[key] = value unless key.nil?
182
- end
183
- end
184
- end
185
- end
186
-
187
- inihash
188
- end
189
-
190
- #
191
- # Reading comments from file
192
- #
193
- # +path+ is a path to the ini file
194
- #
195
- # Returns a string with comments from the beginning of the
196
- # ini file.
197
- #
198
- def Ini.read_comment_from_file(path)
199
- comment = ""
200
-
201
- IO.foreach(path) do |line|
202
- line.strip!
203
- break unless line[0,1] == "#" or line == ""
204
-
205
- comment << "#{line[1, line.length ].strip}\n"
206
- end
207
-
208
- comment
209
- end
210
-
211
- #
212
- # Writing a ini hash into a file
213
- #
214
- # +path+ is a path to the ini file
215
- # +inihash+ is a hash representing the ini File. Default is a empty hash.
216
- # +comment+ is a string with comments which appear on the
217
- # top of the file. Each line will get a "#" before.
218
- # Default is no comment.
219
- #
220
- def Ini.write_to_file(path, inihash={}, comment=nil)
221
- raise TypeError, "String expected" unless comment.is_a? String or comment.nil?
222
-
223
- raise TypeError, "Hash expected" unless inihash.is_a? Hash
224
- File.open(path, "w") { |file|
225
-
226
- unless comment.nil?
227
- comment.each do |line|
228
- file << "# #{line}"
229
- end
230
- end
231
-
232
- file << Ini.to_s(inihash)
233
- }
234
- end
235
-
236
- #
237
- # Turn a hash (up to 2 levels deepness) into a ini string
238
- #
239
- # +inihash+ is a hash representing the ini File. Default is a empty hash.
240
- #
241
- # Returns a string in the ini file format.
242
- #
243
- def Ini.to_s(inihash={})
244
- str = ""
245
-
246
- inihash.each do |key, value|
247
-
248
- if value.is_a? Hash
249
- str << "[#{key.to_s}]\n"
250
-
251
- value.each do |under_key, under_value|
252
- str << "#{under_key.to_s}=#{under_value.to_s unless under_value.nil?}\n"
253
- end
254
-
255
- else
256
- str << "#{key.to_s}=#{value.to_s unless value2.nil?}\n"
257
- end
258
- end
259
-
260
- str
261
- end
262
-
263
- end
264
-
@@ -1 +0,0 @@
1
- require 'facets/instantize'
@@ -1,95 +0,0 @@
1
- # = Instantize
2
- #
3
- # Instantize converts module methods into instance methods
4
- # such that the first parameter is passed self at the instance level.
5
- # This promotes DRY programming when wishing to offer both an inheritable
6
- # and a module callable procedure.
7
- #
8
- # module MyModule
9
- # extend Instantize
10
- #
11
- # def self.jumble( obj, arg )
12
- # obj + arg
13
- # end
14
- # end
15
- #
16
- # class String
17
- # include MyModule
18
- # end
19
- #
20
- # MyModule.jumble( "Try", "Me" ) #=> "TryMe"
21
- #
22
- # "Try".jumble( "Me" ) #=> 'TryMe'
23
- #
24
- # == Notes
25
- #
26
- # This module used to be called PromoteSelf. Instantize is more descriptive, but
27
- # a better name is probably still out there.
28
- #
29
- # == Authors
30
- #
31
- # * Thomas Sawyer
32
- #
33
- # == Copying
34
- #
35
- # Copyright (c) 2005 Thomas Sawyer
36
- #
37
- # Ruby License
38
- #
39
- # This module is free software. You may use, modify, and/or redistribute this
40
- # software under the same terms as Ruby.
41
- #
42
- # This program is distributed in the hope that it will be useful, but WITHOUT
43
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
44
- # FOR A PARTICULAR PURPOSE.
45
-
46
-
47
- # = Instantize
48
- #
49
- # Instantize converts module methods into instance methods
50
- # such that the first parameter is passed self at the instance level.
51
- # This promotes DRY programming when wishing to offer both an inheritable
52
- # and a module callable procedure.
53
- #
54
- # module MyModule
55
- # extend Instantize
56
- #
57
- # def self.jumble( obj, arg )
58
- # obj + arg
59
- # end
60
- # end
61
- #
62
- # class String
63
- # include MyModule
64
- # end
65
- #
66
- # MyModule.jumble( "Try", "Me" ) #=> "TryMe"
67
- #
68
- # "Try".jumble( "Me" ) #=> 'TryMe'
69
- #
70
- # == Notes
71
- #
72
- # This module used to be called PromoteSelf. Instantize is more descriptive, but
73
- # a better name is probably still out there.
74
- #
75
- module Instantize
76
-
77
- def self.append_features(mod)
78
- mod.extend self
79
- end
80
-
81
- def singleton_method_added( meth )
82
- d = %{
83
- def #{meth}(*args)
84
- #{self.name}.#{meth}(self,*args)
85
- end
86
- }
87
- self.class_eval d
88
- super(meth)
89
- end
90
-
91
- end
92
-
93
- # Constant Alias
94
- Instantise = Instantize
95
-
@@ -1,282 +0,0 @@
1
- # = Interval
2
- #
3
- # While Ruby support the Range class out of the box, is does not quite
4
- # fullfil the role od a real Interval class. For instance, it does
5
- # not support excluding the front sentinel. This is because Range
6
- # also tries to do triple duty as a simple Sequence and as a simple Tuple-Pair,
7
- # thus limiting its potential as an Interval. The Interval class remedies
8
- # the situation by commiting to interval behavior, and then extends the class'
9
- # capabilites beyond that of the standard Range in ways that naturally
10
- # fall out of that.
11
- #
12
- # Range depends on two methods: #succ and #<=>. If numeric
13
- # ranges were the only concern, those could just as well be #+ and #<=>,
14
- # but esoteric forms make that unfeasible --the obvious example being a String
15
- # range. But a proper Interval class requires mathematical continuation,
16
- # thus the Interval depends on #+ and #<=>, as well as #- as the inverse of #+.
17
- #
18
- # i = Interval.new(1,5)
19
- # i.to_a #=> [1,2,3,4,5]
20
- #
21
- # i = Interval[0,5]
22
- # i.to_a(2) #=> [0,2,4]
23
- #
24
- # i = Interval[1,5]
25
- # i.to_a(-1) #=> [5,4,3,2,1]
26
- #
27
- # i = Interval[1,3]
28
- # i.to_a(1,2) #=> [1.0,1.5,2.0,2.5,3.0]
29
- #
30
- # == Authors
31
- #
32
- # * Thomas Sawyer
33
- #
34
- # == Todo
35
- #
36
- # * Still need to tie in Infinity.
37
- #
38
- # == Copying
39
- #
40
- # Copyright (c) 2004 Thomas Sawyer
41
- #
42
- # Ruby License
43
- #
44
- # This module is free software. You may use, modify, and/or redistribute this
45
- # software under the same terms as Ruby.
46
- #
47
- # This program is distributed in the hope that it will be useful, but WITHOUT
48
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
49
- # FOR A PARTICULAR PURPOSE.
50
-
51
- require 'facets/multiton'
52
- require 'facets/enumerablepass'
53
- #require 'facets/infinity'
54
-
55
- # = Interval
56
- #
57
- # While Ruby support the Range class out of the box, is does not quite
58
- # fullfil the role od a real Interval class. For instance, it does
59
- # not support excluding the front sentinel. This is because Range
60
- # also tries to do triple duty as a simple Sequence and as a simple Tuple-Pair,
61
- # thus limiting its potential as an Interval. The Interval class remedies
62
- # the situation by commiting to interval behavior, and then extends the class'
63
- # capabilites beyond that of the standard Range in ways that naturally
64
- # fall out of that.
65
- #
66
- # Range depends on two methods: #succ and #<=>. If numeric
67
- # ranges were the only concern, those could just as well be #+ and #<=>,
68
- # but esoteric forms make that unfeasible --the obvious example being a String
69
- # range. But a proper Interval class requires mathematical continuation,
70
- # thus the Interval depends on #+ and #<=>, as well as #- as the inverse of #+.
71
- #
72
- # i = Interval.new(1,5)
73
- # i.to_a #=> [1,2,3,4,5]
74
- #
75
- # i = Interval[0,5]
76
- # i.to_a(2) #=> [0,2,4]
77
- #
78
- # i = Interval[1,5]
79
- # i.to_a(-1) #=> [5,4,3,2,1]
80
- #
81
- # i = Interval[1,3]
82
- # i.to_a(1,2) #=> [1.0,1.5,2.0,2.5,3.0]
83
-
84
- class Interval
85
-
86
- include Multiton
87
- include EnumerablePass
88
-
89
- def self.[]( *args )
90
- self.new( *args )
91
- end
92
-
93
- def initialize(first, last, exclude_first=false, exclude_last=false )
94
- raise ArgumentError, "bad value for interval" if first.class != last.class
95
- @first = first
96
- @last = last
97
- @exclude_first = exclude_first
98
- @exclude_last = exclude_last
99
- @direction = (@last <=> @first)
100
- end
101
-
102
- # Returns a two element array of first and last sentinels.
103
- #
104
- # (0..10).sentinels #=> [0,10]
105
- #
106
- def sentinels
107
- return [@first, @last]
108
- end
109
-
110
- # Returns the first or last sentinal of the interval.
111
- def first ; @first ; end
112
- def last ; @last ; end
113
-
114
- #
115
- def exclude_first? ; @exclude_first ; end
116
- def exclude_last? ; @exclude_last ; end
117
-
118
- # (IMHO) these should be deprectated
119
- alias_method( :begin, :first )
120
- alias_method( :end, :last )
121
- alias_method( :exclude_begin?, :exclude_first? )
122
- alias_method( :exclude_end?, :exclude_last? )
123
-
124
- # Returns +true+ if the start and end sentinels are equal and the interval is closed; otherwise +false+.
125
- def degenerate? ; @direction == 0 and ! (@exclusive_first or @exclusive_last) ; end
126
-
127
- # Returns +true+ if the start and end sentinels are equal and the interval is open; otherwise +false+.
128
- def null? ; @direction == 0 and @exclusive_first and @exclusive_last ; end
129
-
130
- # Returns the direction of the interval indicated by +1, 0 or -1.
131
- #
132
- # (1..5).direction #=> 1
133
- # (5..1).direction #=> -1
134
- # (1..1).direction #=> 0
135
- #
136
- def direction ; @direction ; end
137
-
138
- # Returns a new interval inclusive of of both sentinels.
139
- def closed; Interval.new(@first, @last, true, true) ; end
140
-
141
- # Returns a new interval exclusive of both sentinels.
142
- def opened; Interval.new(@first, @last, true, true) ; end
143
-
144
- # Returns a new interval with either the first or the last sentinel exclusive.
145
- # If the parameter is false, the deafult, then the first sentinel is excluded;
146
- # if the parameter is true, the last sentinel is excluded.
147
- def half_closed(e=false)
148
- e ? Interval.new(@first, @last, true, false) : Interval.new(@first, @last, false, true)
149
- end
150
-
151
- # Returns a new interval with one of the two sentinels opened or closed
152
- def first_closed ; Interval.new(@first, @last, false, true) ; end
153
- def last_closed ; Interval.new(@first, @last, true, false) ; end
154
- def first_opened ; Interval.new(@first, @last, true, false) ; end
155
- def last_opened ; Interval.new(@first, @last, false, true) ; end
156
-
157
- # Unary shorthands. These return a new interval exclusive of first,
158
- # last or both sentinels, repectively.
159
- def +@ ; Interval.new(first, last, true, false) ; end
160
- def -@ ; Interval.new(first, last, false, true) ; end
161
- def ~@ ; Interval.new(first, last, true, true) ; end
162
-
163
- # Returns a new interval with the sentinels reversed.
164
- #
165
- # (0..10).reversed #=> 10..0
166
- #
167
- def reversed
168
- Interval.new(@last, @first, true, true)
169
- end
170
-
171
- # Returns the length of the interval as the difference between
172
- # the first and last elements. Returns +nil+ if the sentinal objects
173
- # do not support distance comparison (#distance).
174
- # TODO: Add +n+ parameter to count segmentations like those produced by #each.
175
- def distance
176
- @last - @first
177
- #if @last.respond_to?( :distance )
178
- # @last.distance( @first )
179
- #else
180
- # #self.to_a.length
181
- #end
182
- end
183
- alias_method( :length, :distance )
184
- alias_method( :size, :distance )
185
-
186
- # Returns the lesser of the first and last sentinals.
187
- def min
188
- ((@first <=> @last) == -1) ? @first : @last
189
- end
190
-
191
- # Returns the greater of the first and last sentinals.
192
- def max
193
- ((@first <=> @last) == 1) ? @first : @last
194
- end
195
-
196
- # Returns true or false if the element is part of the interval.
197
- def include?(x)
198
- # todo: infinity?
199
- tf = exclude_first? ? 1 : 0
200
- tl = exclude_last? ? -1 : 0
201
- (x <=> first) >= tf and (x <=> last) <= tl
202
- end
203
- alias_method( :===, :include? )
204
- alias_method( :member?, :include? )
205
-
206
- =begin
207
- # def include?(x)
208
- # tf = exclude_first? ? 1 : 0
209
- # tl = exclude_last? ? -1 : 0
210
- # # if other classes handled Infinity in their <=> method
211
- # # (which probably they should) this clause would not be required
212
- # if first.kind_of?(InfinityClass)
213
- # ft = ((first <=> x) <= tf)
214
- # else
215
- # ft = (x <=> first) >= tf
216
- # end
217
- # if last.kind_of?(InfinityClass)
218
- # fl = ((last <=> x) >= tl)
219
- # else
220
- # fl = (x <=> last) <= tl
221
- # end
222
- # ft && fl
223
- # end
224
- =end
225
-
226
- # Iterates over the interval, passing each _n_th element to the block.
227
- # If n is not given then n defaults to 1. Each _n_th step is determined
228
- # by invoking +\++ or +\-+ n, depending on the direction of the interval.
229
- # If n is negative the iteration is preformed in reverse form end sentinal
230
- # to front sentinal. A second parameter, d, can be given in which case
231
- # the applied step is calculated as a fraction of the interval's length
232
- # times n / d. This allows iteration over the whole interval in equal sized
233
- # segments.
234
- #
235
- # 1..5.each { |e| ... } #=> 1 2 3 4 5
236
- # 1..5.each(2) { |e| ... } #=> 1 3 5
237
- # 1..5.each(1,2) { |e| ... } #=> 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
238
- #
239
- def each(n=1, d=nil) # :yield:
240
- return (n < 0 ? @last : @first) if degenerate? # is this right for all values of n ?
241
- s = d ? self.length.to_f * (n.to_f / d.to_f) : n.abs
242
- raise "Cannot iterate over zero length steps." if s == 0
243
- s = s * @direction
244
- if n < 0
245
- e = @exclude_last ? @last - s : @last
246
- #e = @exclude_last ? @last.pred(s) : @last
247
- t = @exclude_last ? 1 : 0
248
- #while e.cmp(@first) >= t
249
- while (e <=> @first) >= t
250
- yield(e)
251
- e -= s
252
- #e = e.pred(s)
253
- end
254
- else
255
- e = @exclude_first ? @first + s : @first
256
- #e = @exclude_first ? @first.succ(s) : @first
257
- t = @exclude_last ? -1 : 0
258
- #while e.cmp(@last) <= t
259
- while (e <=> @last) <= t
260
- yield(e)
261
- e += s
262
- #e = e.succ(s)
263
- end
264
- end
265
- end
266
- alias_method( :step, :each )
267
-
268
- # Should there be a #reverse_each ?
269
- # Since #each can now take a negative argument, this isn't really needed.
270
- # Should it exist anyway and routed to #each?
271
- # Also, alias_method( :reverse_step, :reverse_each )
272
-
273
- # Compares two intervals to see if they are equal
274
- def eql?(other)
275
- return false unless @first == other.first
276
- return false unless @last == other.last
277
- return false unless @exclude_first == other.exclude_first?
278
- return false unless @exclude_last == other.exclude_last?
279
- true
280
- end
281
-
282
- end