eymiha_util 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/gem_package.rb +1 -1
  2. data/html/classes/BaseEnvelope.html +203 -203
  3. data/html/classes/BaseEnvelope.src/M000001.html +15 -15
  4. data/html/classes/BaseEnvelope.src/M000002.html +15 -15
  5. data/html/classes/BaseEnvelope.src/M000003.html +15 -15
  6. data/html/classes/Enum.html +133 -0
  7. data/html/classes/Envelope.html +328 -328
  8. data/html/classes/Envelope.src/M000016.html +15 -15
  9. data/html/classes/Envelope.src/M000017.html +15 -15
  10. data/html/classes/Envelope.src/M000018.html +15 -15
  11. data/html/classes/Envelope.src/M000019.html +15 -15
  12. data/html/classes/Envelope.src/M000020.html +15 -15
  13. data/html/classes/Envelope.src/M000021.html +15 -15
  14. data/html/classes/Envelope.src/M000023.html +15 -15
  15. data/html/classes/EnvelopeException.html +118 -118
  16. data/html/classes/ForwardReference.html +203 -203
  17. data/html/classes/ForwardReference.src/M000024.html +20 -20
  18. data/html/classes/ForwardReference.src/M000025.html +17 -17
  19. data/html/classes/ForwardReferencer.html +173 -173
  20. data/html/classes/ForwardReferencing.html +319 -319
  21. data/html/classes/ForwardReferencing.src/M000026.html +19 -19
  22. data/html/classes/ForwardReferencing.src/M000027.html +19 -19
  23. data/html/classes/ForwardReferencing.src/M000028.html +19 -19
  24. data/html/classes/ForwardReferencing.src/M000029.html +31 -31
  25. data/html/classes/ForwardReferencing.src/M000030.html +17 -17
  26. data/html/classes/ForwardReferencing.src/M000031.html +24 -24
  27. data/html/classes/ForwardReferencing.src/M000032.html +17 -17
  28. data/html/classes/ForwardReferencing.src/M000033.html +17 -17
  29. data/html/classes/ForwardReferencing.src/M000034.html +17 -17
  30. data/html/classes/Histogram.html +324 -324
  31. data/html/classes/Histogram.src/M000007.html +15 -15
  32. data/html/classes/Histogram.src/M000008.html +15 -15
  33. data/html/classes/Histogram.src/M000009.html +15 -15
  34. data/html/classes/Histogram.src/M000010.html +15 -15
  35. data/html/classes/Histogram.src/M000011.html +15 -15
  36. data/html/classes/Histogram.src/M000012.html +15 -15
  37. data/html/classes/Histogram.src/M000013.html +15 -15
  38. data/html/classes/Histogram.src/M000014.html +15 -15
  39. data/html/classes/Histogram.src/M000015.html +15 -15
  40. data/html/classes/HistogramException.html +117 -117
  41. data/html/classes/MethodicHash.html +221 -221
  42. data/html/classes/MethodicHash.src/M000004.html +15 -15
  43. data/html/classes/MethodicHash.src/M000005.html +15 -15
  44. data/html/classes/MethodicHash.src/M000006.html +15 -15
  45. data/html/created.rid +1 -1
  46. data/html/files/lib/enum_rb.html +123 -0
  47. data/html/files/lib/envelope_rb.html +108 -108
  48. data/html/files/lib/forward_referencing_rb.html +119 -119
  49. data/html/files/lib/histogram_rb.html +108 -108
  50. data/html/files/lib/methodic_hash_rb.html +139 -139
  51. data/html/fr_class_index.html +35 -34
  52. data/html/fr_file_index.html +30 -29
  53. data/html/fr_method_index.html +59 -59
  54. data/html/index.html +23 -23
  55. data/html/rdoc-style.css +207 -207
  56. data/lib/enum.rb +57 -0
  57. data/test/tc_enum.rb +70 -0
  58. metadata +6 -2
data/lib/enum.rb ADDED
@@ -0,0 +1,57 @@
1
+ # Enums are used to build a sets of enumerated values.
2
+ #
3
+ # Numeric and bitwise enums are provided, and include provisions for assigned
4
+ # values and the allowance of gaps.
5
+ #
6
+ # enum %w(N1 N2 +2 N3 N4 =7 N5 N6 3 N7)
7
+ #
8
+ # gives N1 = 0, N2 = 1, N3 = 4, N4 = 5, N5 = 7, N6 = 8 and N7 = 3
9
+ #
10
+ # enum_bitwise %w(B1 B2 +2 B3 B4 =7 B5 B6 3 B7)
11
+ #
12
+ # gives B1 = 1, B2 = 2, B3 = 16, B4 = 32, B5 = 128, B6 = 256 and B7 = 8
13
+ class Enum
14
+
15
+ private
16
+
17
+ def self.build(arguments = {})
18
+ code = <<EOF
19
+ def #{arguments[:method]}(*args)
20
+ offset = 0
21
+ bias = 0
22
+ args.flatten.each_with_index do |const,i|
23
+ case const
24
+ when /^\\+(\\d+)$/
25
+ offset = $1.to_i
26
+ bias += 1
27
+ when /^(\\=)?(\\d+)$/
28
+ offset = $2.to_i - i
29
+ else
30
+ class_eval %(#{arguments[:enum_type]})
31
+ end
32
+ end
33
+ end
34
+ EOF
35
+ arguments[:object].class_eval(code)
36
+ end
37
+
38
+ numeric = '#{const} = #{i+offset-bias}'
39
+ bitwise = '#{const} = #{2**(i+offset-bias)}'
40
+
41
+ Enum.build({ :object => Object,
42
+ :method => "self.enum",
43
+ :enum_type => numeric })
44
+
45
+ Enum.build({ :object => Object,
46
+ :method => "self.bitwise_enum",
47
+ :enum_type => bitwise })
48
+
49
+ Enum.build({ :object => Module,
50
+ :method => "enum",
51
+ :enum_type => numeric })
52
+
53
+ Enum.build({ :object => Module,
54
+ :method => "bitwise_enum",
55
+ :enum_type => bitwise })
56
+
57
+ end
data/test/tc_enum.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'test/unit'
2
+
3
+ require 'enum'
4
+
5
+ module Module_test
6
+ enum %w(MA1 MA2 +2 MA3 MA4 =7 MA5 MA6 3 MA7)
7
+ bitwise_enum %w(MB1 MB2 +2 MB3 MB4 =7 MB5 MB6 3 MB7)
8
+ end
9
+
10
+ class TC_enum_module < Test::Unit::TestCase
11
+
12
+ include Module_test
13
+
14
+ def test_enum
15
+ assert([ MA1, MA2, MA3, MA4, MA5, MA6, MA7 ] ==
16
+ [ 0, 1, 4, 5, 7, 8, 3 ],
17
+ "enum (instance) value assignments")
18
+ end
19
+ end
20
+
21
+ class TC_bitwise_enum_module < Test::Unit::TestCase
22
+
23
+ include Module_test
24
+
25
+ def test_bitwise_enum
26
+ assert([ MB1, MB2, MB3, MB4, MB5, MB6, MB7 ] ==
27
+ [ 1, 2, 16, 32, 128, 256, 8 ],
28
+ "bitwise_enum (instance) value assignment")
29
+ end
30
+ end
31
+
32
+ class TC_enum < Test::Unit::TestCase
33
+
34
+ enum %w(A1 A2 +2 A3 A4 =7 A5 A6 3 A7)
35
+
36
+ def test_enum
37
+ assert([ A1, A2, A3, A4, A5, A6, A7 ] ==
38
+ [ 0, 1, 4, 5, 7, 8, 3 ],
39
+ "enum (class) value assignments")
40
+ end
41
+ end
42
+
43
+ class TC_bitwise_enum < Test::Unit::TestCase
44
+
45
+ bitwise_enum %w(B1 B2 +2 B3 B4 =7 B5 B6 3 B7)
46
+
47
+ def test_bitwise_enum
48
+ assert([ B1, B2, B3, B4, B5, B6, B7 ] ==
49
+ [ 1, 2, 16, 32, 128, 256, 8 ],
50
+ "bitwise_enum (class) value assignment")
51
+ end
52
+ end
53
+
54
+ class TC_enum_use < Test::Unit::TestCase
55
+ def test_enum
56
+ assert([ TC_enum::A1, TC_enum::A2, TC_enum::A3, TC_enum::A4, TC_enum::A5,
57
+ TC_enum::A6, TC_enum::A7 ] == [ 0, 1, 4, 5, 7, 8, 3 ],
58
+ "enum value assignments")
59
+ end
60
+ end
61
+
62
+ class TC_bitwise_enum_use < Test::Unit::TestCase
63
+ def test_bitwise_enum
64
+ assert([ TC_bitwise_enum::B1, TC_bitwise_enum::B2, TC_bitwise_enum::B3,
65
+ TC_bitwise_enum::B4, TC_bitwise_enum::B5, TC_bitwise_enum::B6,
66
+ TC_bitwise_enum::B7 ] == [ 1, 2, 16, 32, 128, 256, 8 ],
67
+ "bitwise_enum value assignment")
68
+ end
69
+ end
70
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: eymiha_util
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.5
7
- date: 2008-02-08 00:00:00 -05:00
6
+ version: 0.1.6
7
+ date: 2008-04-09 00:00:00 -04:00
8
8
  summary: Eymiha general utility classes and methods
9
9
  require_paths:
10
10
  - lib
@@ -31,10 +31,12 @@ authors:
31
31
  files:
32
32
  - gem_package.rb
33
33
  - rakefile.rb
34
+ - lib/enum.rb
34
35
  - lib/envelope.rb
35
36
  - lib/forward_referencing.rb
36
37
  - lib/histogram.rb
37
38
  - lib/methodic_hash.rb
39
+ - test/tc_enum.rb
38
40
  - test/tc_envelope.rb
39
41
  - test/tc_forward_referencing.rb
40
42
  - test/tc_histogram.rb
@@ -45,6 +47,7 @@ files:
45
47
  - html/classes/BaseEnvelope.src/M000001.html
46
48
  - html/classes/BaseEnvelope.src/M000002.html
47
49
  - html/classes/BaseEnvelope.src/M000003.html
50
+ - html/classes/Enum.html
48
51
  - html/classes/Envelope.html
49
52
  - html/classes/Envelope.src
50
53
  - html/classes/Envelope.src/M000016.html
@@ -91,6 +94,7 @@ files:
91
94
  - html/created.rid
92
95
  - html/files
93
96
  - html/files/lib
97
+ - html/files/lib/enum_rb.html
94
98
  - html/files/lib/envelope_rb.html
95
99
  - html/files/lib/forward_referencing_rb.html
96
100
  - html/files/lib/histogram_rb.html