nrser 0.0.30 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser.rb +56 -12
  3. data/lib/nrser/collection.rb +4 -7
  4. data/lib/nrser/ext.rb +5 -0
  5. data/lib/nrser/{refinements → ext}/enumerable.rb +11 -9
  6. data/lib/nrser/ext/pathname.rb +74 -0
  7. data/lib/nrser/{refinements → ext}/tree.rb +2 -26
  8. data/lib/nrser/functions.rb +18 -0
  9. data/lib/nrser/{array.rb → functions/array.rb} +2 -3
  10. data/lib/nrser/{binding.rb → functions/binding.rb} +0 -2
  11. data/lib/nrser/functions/enumerable.rb +355 -0
  12. data/lib/nrser/functions/enumerable/find_all_map.rb +33 -0
  13. data/lib/nrser/functions/enumerable/find_map.rb +53 -0
  14. data/lib/nrser/functions/exception.rb +17 -0
  15. data/lib/nrser/{hash.rb → functions/hash.rb} +0 -0
  16. data/lib/nrser/functions/hash/bury.rb +147 -0
  17. data/lib/nrser/{hash → functions/hash}/deep_merge.rb +5 -5
  18. data/lib/nrser/{hash → functions/hash}/except_keys.rb +2 -0
  19. data/lib/nrser/{hash → functions/hash}/guess_label_key_type.rb +3 -1
  20. data/lib/nrser/{hash → functions/hash}/slice_keys.rb +3 -1
  21. data/lib/nrser/{hash → functions/hash}/stringify_keys.rb +2 -0
  22. data/lib/nrser/{hash → functions/hash}/symbolize_keys.rb +3 -1
  23. data/lib/nrser/{hash → functions/hash}/transform_keys.rb +3 -1
  24. data/lib/nrser/functions/merge_by.rb +29 -0
  25. data/lib/nrser/{object.rb → functions/object.rb} +0 -0
  26. data/lib/nrser/{object → functions/object}/as_array.rb +2 -0
  27. data/lib/nrser/{object → functions/object}/as_hash.rb +7 -5
  28. data/lib/nrser/{object → functions/object}/truthy.rb +46 -7
  29. data/lib/nrser/{open_struct.rb → functions/open_struct.rb} +0 -0
  30. data/lib/nrser/functions/path.rb +150 -0
  31. data/lib/nrser/{proc.rb → functions/proc.rb} +1 -22
  32. data/lib/nrser/functions/string.rb +297 -0
  33. data/lib/nrser/functions/string/looks_like.rb +44 -0
  34. data/lib/nrser/{text.rb → functions/text.rb} +0 -0
  35. data/lib/nrser/{text → functions/text}/indentation.rb +2 -16
  36. data/lib/nrser/{text → functions/text}/lines.rb +1 -2
  37. data/lib/nrser/{text → functions/text}/word_wrap.rb +2 -4
  38. data/lib/nrser/{tree.rb → functions/tree.rb} +0 -0
  39. data/lib/nrser/{tree → functions/tree}/each_branch.rb +6 -7
  40. data/lib/nrser/functions/tree/leaves.rb +92 -0
  41. data/lib/nrser/{tree → functions/tree}/map_branches.rb +31 -32
  42. data/lib/nrser/functions/tree/map_leaves.rb +56 -0
  43. data/lib/nrser/{tree → functions/tree}/map_tree.rb +9 -20
  44. data/lib/nrser/{tree → functions/tree}/transform.rb +0 -10
  45. data/lib/nrser/logger.rb +9 -10
  46. data/lib/nrser/message.rb +3 -7
  47. data/lib/nrser/meta.rb +2 -0
  48. data/lib/nrser/meta/class_attrs.rb +3 -9
  49. data/lib/nrser/meta/props.rb +19 -19
  50. data/lib/nrser/meta/props/base.rb +4 -10
  51. data/lib/nrser/meta/props/prop.rb +12 -28
  52. data/lib/nrser/no_arg.rb +1 -3
  53. data/lib/nrser/refinements.rb +5 -0
  54. data/lib/nrser/refinements/array.rb +5 -17
  55. data/lib/nrser/refinements/enumerator.rb +1 -3
  56. data/lib/nrser/refinements/hash.rb +3 -15
  57. data/lib/nrser/refinements/object.rb +2 -2
  58. data/lib/nrser/refinements/open_struct.rb +0 -2
  59. data/lib/nrser/refinements/pathname.rb +3 -46
  60. data/lib/nrser/refinements/set.rb +2 -6
  61. data/lib/nrser/refinements/string.rb +2 -2
  62. data/lib/nrser/rspex.rb +16 -13
  63. data/lib/nrser/types.rb +6 -20
  64. data/lib/nrser/types/any.rb +0 -1
  65. data/lib/nrser/types/booleans.rb +1 -1
  66. data/lib/nrser/types/combinators.rb +5 -5
  67. data/lib/nrser/types/in.rb +0 -21
  68. data/lib/nrser/types/responds.rb +1 -0
  69. data/lib/nrser/types/trees.rb +1 -0
  70. data/lib/nrser/version.rb +2 -3
  71. data/spec/nrser/{template_spec.rb → functions/binding/template_spec.rb} +0 -0
  72. data/spec/nrser/functions/enumerable/find_all_map_spec.rb +28 -0
  73. data/spec/nrser/functions/enumerable/find_bounded_spec.rb +70 -0
  74. data/spec/nrser/functions/enumerable/find_map_spec.rb +38 -0
  75. data/spec/nrser/functions/enumerable/find_only_spec.rb +25 -0
  76. data/spec/nrser/functions/enumerable/to_h_by_spec.rb +28 -0
  77. data/spec/nrser/{format_exception_spec.rb → functions/exception/format_exception_spec.rb} +0 -0
  78. data/spec/nrser/{hash → functions/hash}/bury_spec.rb +0 -0
  79. data/spec/nrser/{hash → functions/hash}/guess_label_key_type_spec.rb +0 -0
  80. data/spec/nrser/{hash_spec.rb → functions/hash_spec.rb} +0 -7
  81. data/spec/nrser/{merge_by_spec.rb → functions/merge_by_spec.rb} +0 -0
  82. data/spec/nrser/{truthy_spec.rb → functions/object/truthy_spec.rb} +0 -0
  83. data/spec/nrser/{open_struct_spec.rb → functions/open_struct_spec.rb} +0 -0
  84. data/spec/nrser/{string → functions/string}/common_prefix_spec.rb +0 -0
  85. data/spec/nrser/{string → functions/string}/looks_like_spec.rb +0 -0
  86. data/spec/nrser/{truncate_spec.rb → functions/string/truncate_spec.rb} +0 -0
  87. data/spec/nrser/{text → functions/text}/dedent/gotchas_spec.rb +0 -0
  88. data/spec/nrser/{text → functions/text}/dedent_spec.rb +0 -0
  89. data/spec/nrser/{indent_spec.rb → functions/text/indent_spec.rb} +0 -0
  90. data/spec/nrser/{tree → functions/tree}/each_branch_spec.rb +0 -0
  91. data/spec/nrser/{tree → functions/tree}/leaves_spec.rb +0 -0
  92. data/spec/nrser/{tree → functions/tree}/map_branch_spec.rb +0 -0
  93. data/spec/nrser/{tree → functions/tree}/map_tree_spec.rb +0 -0
  94. data/spec/nrser/{tree → functions/tree}/transform_spec.rb +0 -0
  95. data/spec/nrser/{tree → functions/tree}/transformer_spec.rb +0 -0
  96. data/spec/nrser/meta/class_attrs_spec.rb +12 -14
  97. data/spec/spec_helper.rb +2 -3
  98. metadata +136 -110
  99. data/lib/nrser/enumerable.rb +0 -288
  100. data/lib/nrser/exception.rb +0 -7
  101. data/lib/nrser/hash/bury.rb +0 -154
  102. data/lib/nrser/merge_by.rb +0 -26
  103. data/lib/nrser/string.rb +0 -294
  104. data/lib/nrser/string/looks_like.rb +0 -51
  105. data/lib/nrser/tree/leaves.rb +0 -92
  106. data/lib/nrser/tree/map_leaves.rb +0 -63
  107. data/spec/nrser/enumerable_spec.rb +0 -111
@@ -1,63 +0,0 @@
1
- module NRSER
2
-
3
- # Eigenclass (Singleton Class)
4
- # ========================================================================
5
- #
6
- class << self
7
-
8
- def map_leaves tree, &block
9
- NRSER::Types.tree.check tree
10
-
11
- _internal_map_leaves tree, key_path: [], &block
12
- end # #map_leaves
13
-
14
- private
15
- # ========================================================================
16
-
17
- # Internal recursive implementation for {NRSER.leaves}.
18
- #
19
- # @param [#each_pair | (#each_index & #each_with_index)] tree
20
- # Tree to walk.
21
- #
22
- # @param [Array] path
23
- # Key path down to `tree`.
24
- #
25
- # @param [Hash<Array, Object>] results
26
- # New hash to stick results in.
27
- #
28
- # @return [nil]
29
- #
30
- def _internal_map_leaves tree, key_path:, &block
31
- NRSER::Types.match tree,
32
- NRSER::Types.hash_like, ->( hash_like ) {
33
- hash_like.map { |key, value|
34
- new_key_path = [*key_path, key]
35
-
36
- new_value = if NRSER::Types.tree.test( value )
37
- _internal_map_leaves value, key_path: new_key_path, &block
38
- else
39
- block.call new_key_path, value
40
- end
41
-
42
- [key, new_value]
43
- }.to_h
44
- },
45
-
46
- NRSER::Types.array_like, ->( array_like ) {
47
- array_like.each_with_index.map { |value, index|
48
- new_key_path = [*key_path, index]
49
-
50
- if NRSER::Types.tree.test( value )
51
- _internal_map_leaves value, key_path: new_key_path, &block
52
- else
53
- block.call new_key_path, value
54
- end
55
- }
56
- }
57
- end # #_internal_leaves
58
-
59
- # end private
60
-
61
- end # class << self (Eigenclass)
62
-
63
- end # module NRSER
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "NRSER Enumerable Methods" do
4
-
5
- describe NRSER.method(:find_bounded) do
6
-
7
- context "when just :length bounds arg is provided" do
8
- it "returns found elements when length is correct" do
9
- expect(
10
- subject.([1, 2, 3], length: 1) { |i| i == 2 }
11
- ).to eq [2]
12
- end
13
-
14
- it "raises TypeError when length in incorrect" do
15
- expect {
16
- subject.([1, 2, 3], length: 2) { |i| i == 2 }
17
- }.to raise_error TypeError
18
- end
19
- end # when just :length bounds arg is provided
20
-
21
- context "when just :min bounds arg is provided" do
22
- it "returns found elements when min is correct" do
23
- expect(
24
- subject.([1, 2, 3], min: 1) { |i| i == 2 }
25
- ).to eq [2]
26
- end
27
-
28
- it "raises TypeError when min in incorrect" do
29
- expect {
30
- subject.([1, 2, 3], min: 2) { |i| i == 2 }
31
- }.to raise_error TypeError
32
- end
33
- end # when just :min bounds arg is provided
34
-
35
- context "when just :max bounds arg is provided" do
36
- it "returns found elements when max is correct" do
37
- expect(
38
- subject.([1, 2, 3], max: 2) { |i| i >= 2 }
39
- ).to eq [2, 3]
40
- end
41
-
42
- it "raises TypeError when max in incorrect" do
43
- expect {
44
- subject.([1, 2, 3], max: 1) { |i| i >= 2 }
45
- }.to raise_error TypeError
46
- end
47
- end # when just :max bounds arg is provided
48
-
49
-
50
- context "when :min and :max bounds args are both provided" do
51
- it "returns found elements when min and max are correct" do
52
- expect(
53
- subject.([1, 2, 3], min: 1, max: 2) { |i| i >= 2 }
54
- ).to eq [2, 3]
55
- end
56
-
57
- it "raises TypeError when min is incorrect" do
58
- expect {
59
- subject.([1, 2, 3], min: 1, max: 2) { |i| false }
60
- }.to raise_error TypeError
61
- end
62
-
63
- it "raises TypeError when max is incorrect" do
64
- expect {
65
- subject.([1, 2, 3], min: 1, max: 2) { |i| true }
66
- }.to raise_error TypeError
67
- end
68
- end # when :min and :max bounds args are both provided
69
-
70
- end # NRSER.method(:find_bounded)
71
-
72
-
73
- describe NRSER.method(:find_only) do
74
-
75
- it "returns the element when only one is found" do
76
- expect(
77
- subject.call [1, 2, 3] { |i| i == 2 }
78
- ).to be 2
79
- end
80
-
81
- it "raises TypeError when more than one element is found" do
82
- expect {
83
- subject.call [1, 2, 3] { |i| i >= 2 }
84
- }.to raise_error TypeError
85
- end
86
-
87
- it "raises TypeError when no elements are found" do
88
- expect {
89
- subject.call [1, 2, 3] { |i| false }
90
- }.to raise_error TypeError
91
- end
92
-
93
- end # NRSER.method(:find_only)
94
-
95
-
96
- describe NRSER.method(:to_h_by) do
97
-
98
- context "Duplicate keys" do
99
- it "raises NRSER::ConflictError" do
100
- expect {
101
- NRSER.to_h_by([1, 2, 3]) { |i| i % 2 }
102
- }.to raise_error NRSER::ConflictError
103
- end
104
- end # Duplicate keys
105
-
106
-
107
- end # NRSER.to_h_by
108
-
109
-
110
- end # NRSER Enumerable Methods
111
-