nrser 0.1.4 → 0.2.0.pre.0

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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser.rb +3 -0
  3. data/lib/nrser/char.rb +2 -3
  4. data/lib/nrser/char/alpha_numeric_sub.rb +233 -0
  5. data/lib/nrser/ext.rb +1 -0
  6. data/lib/nrser/ext/binding.rb +36 -0
  7. data/lib/nrser/ext/string.rb +29 -0
  8. data/lib/nrser/functions/binding.rb +40 -15
  9. data/lib/nrser/functions/string.rb +17 -1
  10. data/lib/nrser/functions/string/style.rb +71 -0
  11. data/lib/nrser/mean_streak.rb +33 -8
  12. data/lib/nrser/mean_streak/document.rb +221 -36
  13. data/lib/nrser/refinements/binding.rb +3 -4
  14. data/lib/nrser/rspex.rb +3 -17
  15. data/lib/nrser/rspex/example.rb +49 -0
  16. data/lib/nrser/rspex/example_group.rb +61 -33
  17. data/lib/nrser/rspex/example_group/describe_called_with.rb +42 -0
  18. data/lib/nrser/rspex/example_group/describe_spec_file.rb +2 -0
  19. data/lib/nrser/rspex/format.rb +48 -78
  20. data/lib/nrser/types.rb +71 -14
  21. data/lib/nrser/types/attrs.rb +121 -110
  22. data/lib/nrser/types/bounded.rb +3 -2
  23. data/lib/nrser/types/combinators.rb +39 -8
  24. data/lib/nrser/types/hashes.rb +5 -4
  25. data/lib/nrser/types/is.rb +11 -1
  26. data/lib/nrser/types/is_a.rb +11 -2
  27. data/lib/nrser/types/maybe.rb +4 -5
  28. data/lib/nrser/types/nil.rb +1 -10
  29. data/lib/nrser/types/not.rb +53 -0
  30. data/lib/nrser/types/numbers.rb +20 -17
  31. data/lib/nrser/types/shape.rb +75 -0
  32. data/lib/nrser/types/strings.rb +49 -59
  33. data/lib/nrser/types/symbols.rb +13 -18
  34. data/lib/nrser/types/type.rb +32 -9
  35. data/lib/nrser/types/when.rb +102 -0
  36. data/lib/nrser/version.rb +1 -1
  37. data/spec/{nrser → lib/nrser}/collection/each_spec.rb +0 -0
  38. data/spec/{nrser → lib/nrser}/collection/map_spec.rb +0 -0
  39. data/spec/{nrser → lib/nrser}/env/path/insert_spec.rb +0 -0
  40. data/spec/{nrser → lib/nrser}/env/path_spec.rb +0 -0
  41. data/spec/{nrser → lib/nrser}/errors/abstract_method_error_spec.rb +0 -0
  42. data/spec/{nrser → lib/nrser}/functions/binding/template_spec.rb +0 -0
  43. data/spec/{nrser → lib/nrser}/functions/enumerable/find_all_map_spec.rb +0 -0
  44. data/spec/{nrser → lib/nrser}/functions/enumerable/find_bounded_spec.rb +0 -0
  45. data/spec/{nrser → lib/nrser}/functions/enumerable/find_map_spec.rb +0 -0
  46. data/spec/{nrser → lib/nrser}/functions/enumerable/find_only_spec.rb +0 -0
  47. data/spec/{nrser → lib/nrser}/functions/enumerable/include_slice_spec.rb +0 -0
  48. data/spec/{nrser → lib/nrser}/functions/enumerable/to_h_by_spec.rb +0 -0
  49. data/spec/{nrser → lib/nrser}/functions/exception/format_exception_spec.rb +0 -0
  50. data/spec/{nrser → lib/nrser}/functions/hash/bury_spec.rb +0 -0
  51. data/spec/{nrser → lib/nrser}/functions/hash/guess_label_key_type_spec.rb +0 -0
  52. data/spec/{nrser → lib/nrser}/functions/hash_spec.rb +0 -0
  53. data/spec/{nrser → lib/nrser}/functions/merge_by_spec.rb +0 -0
  54. data/spec/{nrser → lib/nrser}/functions/object/truthy_spec.rb +0 -0
  55. data/spec/{nrser → lib/nrser}/functions/open_struct_spec.rb +0 -0
  56. data/spec/{nrser → lib/nrser}/functions/string/common_prefix_spec.rb +0 -0
  57. data/spec/{nrser → lib/nrser}/functions/string/looks_like_spec.rb +0 -0
  58. data/spec/{nrser → lib/nrser}/functions/string/truncate_spec.rb +0 -0
  59. data/spec/{nrser → lib/nrser}/functions/text/dedent/gotchas_spec.rb +0 -0
  60. data/spec/{nrser → lib/nrser}/functions/text/dedent_spec.rb +0 -0
  61. data/spec/{nrser → lib/nrser}/functions/text/indent_spec.rb +0 -0
  62. data/spec/{nrser → lib/nrser}/functions/text/words_spec.rb +0 -0
  63. data/spec/{nrser → lib/nrser}/functions/tree/each_branch_spec.rb +0 -0
  64. data/spec/{nrser → lib/nrser}/functions/tree/leaves_spec.rb +0 -0
  65. data/spec/{nrser → lib/nrser}/functions/tree/map_branch_spec.rb +0 -0
  66. data/spec/{nrser → lib/nrser}/functions/tree/map_tree_spec.rb +0 -0
  67. data/spec/{nrser → lib/nrser}/functions/tree/transform_spec.rb +0 -0
  68. data/spec/{nrser → lib/nrser}/functions/tree/transformer_spec.rb +0 -0
  69. data/spec/{nrser → lib/nrser}/labs/globlin_spec.rb +0 -0
  70. data/spec/{nrser → lib/nrser}/labs/index_spec.rb +0 -0
  71. data/spec/{nrser → lib/nrser}/logger/dest_spec.rb +0 -0
  72. data/spec/{nrser → lib/nrser}/logger/die_spec.rb +0 -0
  73. data/spec/{nrser → lib/nrser}/logger/install_spec.rb +0 -0
  74. data/spec/{nrser → lib/nrser}/logger/level_int_spec.rb +0 -0
  75. data/spec/{nrser → lib/nrser}/logger/level_name_spec.rb +0 -0
  76. data/spec/{nrser → lib/nrser}/logger/level_sym_spec.rb +0 -0
  77. data/spec/{nrser → lib/nrser}/logger/send_log_spec.rb +0 -0
  78. data/spec/{nrser → lib/nrser}/logger/use_spec.rb +0 -0
  79. data/spec/lib/nrser/mean_streak/design_spec.rb +68 -0
  80. data/spec/lib/nrser/mean_streak/identity_instance_spec.rb +21 -0
  81. data/spec/{nrser → lib/nrser}/meta/class_attrs_spec.rb +0 -0
  82. data/spec/{nrser → lib/nrser}/meta/props/to_and_from_data_spec.rb +17 -11
  83. data/spec/{nrser → lib/nrser}/meta/props_spec.rb +0 -0
  84. data/spec/{nrser → lib/nrser}/op/message_spec.rb +0 -0
  85. data/spec/{nrser → lib/nrser}/refinements/array_spec.rb +0 -0
  86. data/spec/{nrser → lib/nrser}/refinements/erb_spec.rb +0 -0
  87. data/spec/{nrser → lib/nrser}/refinements/format_exception_spec.rb +0 -0
  88. data/spec/{nrser → lib/nrser}/refinements/hash_spec.rb +0 -0
  89. data/spec/{nrser → lib/nrser}/refinements/indent_spec.rb +0 -0
  90. data/spec/{nrser → lib/nrser}/refinements/object_spec.rb +0 -0
  91. data/spec/{nrser → lib/nrser}/refinements/pathname_spec.rb +0 -0
  92. data/spec/{nrser → lib/nrser}/refinements/set_spec.rb +0 -0
  93. data/spec/{nrser → lib/nrser}/refinements/truncate_spec.rb +0 -0
  94. data/spec/{nrser → lib/nrser}/types/array_spec.rb +0 -0
  95. data/spec/{nrser → lib/nrser}/types/attrs_spec.rb +0 -0
  96. data/spec/{nrser → lib/nrser}/types/combinators_spec.rb +0 -0
  97. data/spec/{nrser → lib/nrser}/types/is_spec.rb +0 -0
  98. data/spec/{nrser → lib/nrser}/types/pairs_spec.rb +0 -0
  99. data/spec/{nrser → lib/nrser}/types/paths_spec.rb +0 -0
  100. data/spec/{nrser → lib/nrser}/types/strings_spec.rb +0 -0
  101. data/spec/{nrser → lib/nrser}/types/symbols_spec.rb +1 -1
  102. data/spec/{nrser → lib/nrser}/types/tuples_spec.rb +0 -0
  103. data/spec/{nrser → lib/nrser}/types_spec.rb +0 -0
  104. data/spec/{nrser_spec.rb → lib/nrser_spec.rb} +0 -0
  105. metadata +148 -136
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10930bb8b3998cc81f95333c8eb86a102262d84e
4
- data.tar.gz: ff5057aead5992fe1d053e814afd120278b80a4c
3
+ metadata.gz: b51533291e377070a1f4cac954fc49eee602d178
4
+ data.tar.gz: 57c89f078878e050a01dfd8a1b1c00a345de7cb5
5
5
  SHA512:
6
- metadata.gz: f64f47ddbbb195eb13f072aec1f0beb8ff8299dbf9bc40838a2dcb078fd401fc03509c6566f497041ca0b3d5fc95f4b0baee0e7cb390e7238182a0e14e51ee50
7
- data.tar.gz: ba2da8fe57e5d3e9f2c1439fa978957327982624c1a536b1bbf950901783d66808c44042d0f01f4ce7c8ec4333a93fb29904878c3165bc010dd099eddd864265
6
+ metadata.gz: 6305b4adf84631b859377ed9c30d065b617b157299c066a0f8333f9133d979ccf37424cdc16ce3c6cef0219a95e769294cd19148b299f48358bb7934715b7003
7
+ data.tar.gz: 5cbf8bb41e319263a4eda303cdf0651080f628a566f723ca185136b198b3089e89b74b22b3b46f815b553ecb0a770eb48b28c09f935148dde7bd0338dc4201e6
data/lib/nrser.rb CHANGED
@@ -77,3 +77,6 @@ require_relative './nrser/functions'
77
77
  require_relative './nrser/types'
78
78
  require_relative './nrser/meta'
79
79
  require_relative './nrser/mean_streak'
80
+
81
+ # 5. Stuff that *uses* the refinements *at require time* (usually defining
82
+ # constants or meta-programming)
data/lib/nrser/char.rb CHANGED
@@ -18,6 +18,7 @@ module NRSER::Char; end
18
18
  # ============================================================================
19
19
 
20
20
  require_relative './char/special'
21
+ require_relative './char/alpha_numeric_sub'
21
22
 
22
23
 
23
24
  # Definitions
@@ -141,9 +142,7 @@ module NRSER::Char
141
142
  from_i source
142
143
  else
143
144
  raise ArgumentError.new binding.erb <<-END
144
- Expected hex String like '12AB' or Integer, got <%= source.class %>
145
-
146
- Found:
145
+ Expected hex String like '12AB' or Integer, got <%= source.class %>:
147
146
 
148
147
  <%= source.pretty_inspect %>
149
148
 
@@ -0,0 +1,233 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+
5
+
6
+ # Refinements
7
+ # =======================================================================
8
+
9
+ using NRSER
10
+ using NRSER::Types
11
+
12
+
13
+ # Definitions
14
+ # =======================================================================
15
+
16
+ # Lil' structure with useful info and methods for special characters.
17
+ #
18
+ class NRSER::Char::AlphaNumericSub
19
+
20
+ # Attributes
21
+ # ======================================================================
22
+
23
+ # The `a` character (as a length 1 {String}), the `#ord` of which is used
24
+ # to determine the target `#ord` of lower-case alpha (`a-z`) characters for
25
+ # substitution.
26
+ #
27
+ # @return [String]
28
+ # When the sub supports lower-case alpha substitution.
29
+ #
30
+ # @return [nil]
31
+ # When the sub does not support lower-case alpha substitution.
32
+ #
33
+ attr_reader :sub_a
34
+
35
+
36
+ # The `A` character (as a length 1 {String}), the `#ord` of which is used
37
+ # to determine the target `#ord` upper-case alpha (`A-Z`) characters for
38
+ # substitution.
39
+ #
40
+ # @return [String]
41
+ # When the sub supports upper-case alpha substitution.
42
+ #
43
+ # @return [nil]
44
+ # When the sub does not support upper-case alpha substitution.
45
+ #
46
+ attr_reader :sub_A
47
+
48
+
49
+ # The target set's `0` character (as a length 1 {String}), the `#ord` of
50
+ # which is used to determine the target `#ord` of numeric `0-9` characters
51
+ # for substitution.
52
+ #
53
+ # @return [String]
54
+ # When the sub supports numeric substitution.
55
+ #
56
+ # @return [nil]
57
+ # When the sub does not support numeric substitution.
58
+ #
59
+ attr_reader :sub_0
60
+
61
+
62
+ # Map of source character to dest character substitutions to handle cases
63
+ # where a few of the destination alpha-numerics don't follow the "offest
64
+ # from `a`/`A`/`0`" rule.
65
+ #
66
+ # @return [Hash<String, String>]
67
+ # All length 1 UTF-8 strings. Deeply frozen.
68
+ #
69
+ attr_reader :exceptions
70
+
71
+
72
+ # Class Methods
73
+ # ============================================================================
74
+
75
+ # @!group On-Demand Built-In Instances (Class Methods)
76
+ # ----------------------------------------------------------------------------
77
+ #
78
+ # Class functions that create "built-in" instances on demand. Doing it like
79
+ # this side-steps load-order issues with using the refinements.
80
+ #
81
+
82
+ # Instance to substitute alphas with their "Unicode Math Italic"
83
+ # counterpart.
84
+ #
85
+ # @return [NRSER::Char::AlphaNumericSub]
86
+ #
87
+ def self.unicode_math_italic
88
+ @@unicode_math_italic ||= new \
89
+ sub_a: '𝑎',
90
+ sub_A: '𝐴',
91
+ # Doesn't have italic numbers to just don't sub
92
+ exceptions: {
93
+ # The `h` is not in the run
94
+ 'h' => 'ℎ'
95
+ }
96
+ end # .unicode_math_italic
97
+
98
+
99
+ # Instance to substitute alphas with their "Unicode Math Bold"
100
+ # counterpart.
101
+ #
102
+ # @return [NRSER::Char::AlphaNumericSub]
103
+ #
104
+ def self.unicode_math_bold
105
+ @@unicode_math_italic ||= new \
106
+ sub_a: '𝐚',
107
+ sub_A: '𝐀',
108
+ sub_0: '𝟬'
109
+ end # .unicode_math_italic
110
+
111
+
112
+ # Instance to substitute alphas with their "Unicode Math Bold Italic"
113
+ # counterpart.
114
+ #
115
+ # @return [NRSER::Char::AlphaNumericSub]
116
+ #
117
+ def self.unicode_math_bold_italic
118
+ @@unicode_math_italic ||= new \
119
+ sub_A: '𝑨',
120
+ sub_a: '𝒂',
121
+ # Just use the bold numbers since Unicode doesn't seem to have
122
+ # italic numbers
123
+ sub_0: '𝟬'
124
+ end # .unicode_math_italic
125
+
126
+
127
+ # Instance to substitute alphas with their "Unicode Math Bold Italic"
128
+ # counterpart.
129
+ #
130
+ # @return [NRSER::Char::AlphaNumericSub]
131
+ #
132
+ def self.unicode_math_monospace
133
+ @@unicode_math_italic ||= new \
134
+ sub_A: '𝙰',
135
+ sub_a: '𝚊',
136
+ sub_0: '𝟶'
137
+ end # .unicode_math_italic
138
+
139
+ # @!endgroup On-Demand Built-In Instances (Class Methods)
140
+
141
+
142
+ # Constructor
143
+ # ======================================================================
144
+
145
+ # Instantiate a new `Special`.
146
+ #
147
+ # @param [String] char:
148
+ # The actual character as a length 1 UTF-8 string.
149
+ #
150
+ # @param [nil | String] caret:
151
+ # Optional `^X` replacement for control characters, see {#caret} for
152
+ # details.
153
+ #
154
+ # @param [Array<#to_s>] names:
155
+ # Optional names this character goes by.
156
+ #
157
+ # @param [nil | String] symbol:
158
+ # Optional printable unicode character replacement, see {#symbol} for
159
+ # details.
160
+ #
161
+ def initialize sub_a: nil,
162
+ sub_A: nil,
163
+ sub_0: nil,
164
+ exceptions: nil
165
+ binding.locals.tap do |args|
166
+ t.list( t.utf8_char? ).check \
167
+ args.slice( :sub_a, :sub_A, :sub_0 ).values
168
+
169
+ t.hash_?( keys: t.utf8_char, values: t.utf8_char ).check exceptions
170
+
171
+ if args.all?( &:nil? )
172
+ raise ArgumentError.new,
173
+ "All arguments can't be `nil` (sub couldn't do anything)"
174
+ end
175
+ end
176
+
177
+ @sub_a = sub_a.freeze
178
+ @sub_A = sub_A.freeze
179
+ @sub_0 = sub_0.freeze
180
+ @exceptions = if exceptions
181
+ exceptions.each { |k, v| k.freeze; v.freeze }.freeze
182
+ end
183
+ end # #initialize
184
+
185
+
186
+ # Instance Methods
187
+ # ======================================================================
188
+
189
+ # The first of {#names} (if any).
190
+ #
191
+ # @return [nil]
192
+ # When {#names} is empty.
193
+ #
194
+ # @return [String]
195
+ # When {#names} is not empty.
196
+ #
197
+ def sub src
198
+ dest = src.dup
199
+
200
+ if @exceptions
201
+ @exceptions.each do |src_char, dest_char|
202
+ dest.gsub! src_char, dest_char
203
+ end
204
+ end
205
+
206
+ [
207
+ ['a', /[a-z]/],
208
+ ['A', /[A-Z]/],
209
+ ['0', /[0-9]/],
210
+ ].each do |src_char, regexp|
211
+ src_char_ord = src_char.ord
212
+ start_dest_char = instance_variable_get "@sub_#{ src_char }"
213
+
214
+ unless start_dest_char.nil?
215
+ start_dest_char_ord = start_dest_char.ord
216
+
217
+ dest.gsub!( regexp ) { |char|
218
+ NRSER::Char.from_i(
219
+ start_dest_char_ord + (char.ord - src_char_ord)
220
+ )
221
+ }
222
+ end
223
+ end
224
+
225
+ dest
226
+ end
227
+
228
+
229
+ def demo
230
+ sub ['a'..'z', 'A'..'Z', '0'..'9'].map { |_| _.to_a.join }.join
231
+ end
232
+
233
+ end # class NRSER::Char::Special
data/lib/nrser/ext.rb CHANGED
@@ -4,3 +4,4 @@ require_relative './ext/enumerable'
4
4
  require_relative './ext/tree'
5
5
  require_relative './ext/pathname'
6
6
  require_relative './ext/string'
7
+ require_relative './ext/binding'
@@ -0,0 +1,36 @@
1
+ # Extension methods for {Binding}
2
+ #
3
+ module NRSER::Ext::Binding
4
+
5
+ # Calls {NRSER.template} with `self` prepended to `*args`
6
+ #
7
+ # @param (see NRSER.erb)
8
+ # @return (see NRSER.erb)
9
+ #
10
+ def template *args
11
+ NRSER.template self, *args
12
+ end
13
+
14
+ alias_method :erb, :template
15
+
16
+
17
+ # Calls {NRSER.locals} with `self` prepended to `*args`
18
+ #
19
+ # @param (see NRSER.locals)
20
+ # @return (see NRSER.locals)
21
+ #
22
+ def locals *args
23
+ NRSER.locals self, *args
24
+ end
25
+
26
+
27
+ # Calls {NRSER.local_values} with `self` prepended to `*args`
28
+ #
29
+ # @param (see NRSER.local_values)
30
+ # @return (see NRSER.local_values)
31
+ #
32
+ def local_values *args
33
+ NRSER.local_values self, *args
34
+ end
35
+
36
+ end # module NRSER::Ext::Binding
@@ -59,4 +59,33 @@ module NRSER::Ext::String
59
59
  NRSER::words self, *args, &block
60
60
  end
61
61
 
62
+
63
+ # @!group Unicode Stylization
64
+ # ==========================================================================
65
+
66
+ # Calls {NRSER.u_italic} on `self`
67
+ def u_italic
68
+ NRSER.u_italic self
69
+ end
70
+
71
+
72
+ # Calls {NRSER.u_bold} on `self`
73
+ def u_bold
74
+ NRSER.u_bold self
75
+ end
76
+
77
+
78
+ # Calls {NRSER.u_bold_italic} on `self`
79
+ def u_bold_italic
80
+ NRSER.u_bold_italic self
81
+ end
82
+
83
+
84
+ # Calls {NRSER.u_mono} on `self`
85
+ def u_mono
86
+ NRSER.u_mono self
87
+ end
88
+
89
+ # @!endgroup Unicode Stylization
90
+
62
91
  end # module NRSER::Ext::String
@@ -1,18 +1,43 @@
1
1
  module NRSER
2
- class << self
3
-
4
- def erb bnd, str
5
- require 'erb'
6
-
7
- filter_repeated_blank_lines(
8
- with_indent_tagged( dedent( str ) ) { |tagged_str|
9
- ERB.new( tagged_str ).result( bnd )
10
- },
11
- remove_leading: true
12
- )
13
- end # erb
14
-
15
- alias_method :template, :erb
2
+ def self.erb bnd, str
3
+ require 'erb'
16
4
 
17
- end # class << self
5
+ filter_repeated_blank_lines(
6
+ with_indent_tagged( dedent( str ) ) { |tagged_str|
7
+ ERB.new( tagged_str ).result( bnd )
8
+ },
9
+ remove_leading: true
10
+ )
11
+ end # erb
12
+
13
+ singleton_class.send :alias_method, :template, :erb
14
+
15
+
16
+ # Get a {Hash} of all local variable names (as {Symbol}) to values.
17
+ #
18
+ # @param [Binding] bnd
19
+ # Binding to get locals from.
20
+ #
21
+ # @return [Hash<Symbol, Object>]
22
+ #
23
+ def self.locals bnd
24
+ NRSER.map_values( bnd.local_variables ) { |symbol, _|
25
+ bnd.local_variable_get symbol
26
+ }
27
+ end # .locals
28
+
29
+
30
+ # Get a {Array} of all local variable values.
31
+ #
32
+ # Written to facilitate checks like "all argument values are not `nil`".
33
+ #
34
+ # @param [Binding] bnd
35
+ # Binding to get locals from.
36
+ #
37
+ # @return [Array<Object>]
38
+ #
39
+ def self.local_values bnd
40
+ bnd.local_variables.map { |symbol| bnd.local_variable_get symbol }
41
+ end # .locals
42
+
18
43
  end # module NRSER
@@ -1,16 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './string/looks_like'
4
+ require_relative './string/style'
4
5
 
5
6
  module NRSER
6
7
 
7
- # @!group String Functions
8
+ # Constants
9
+ # ==========================================================================
8
10
 
11
+ # Regular expression used to match whitespace.
12
+ #
13
+ # @return [Regexp]
14
+ #
9
15
  WHITESPACE_RE = /\A[[:space:]]*\z/
10
16
 
17
+
18
+ # Unicode ellipsis character.
19
+ #
20
+ # @return [String]
21
+ #
11
22
  UNICODE_ELLIPSIS = '…'
12
23
 
13
24
 
25
+ # @!group String Functions
26
+ # ==========================================================================
27
+
14
28
  def self.whitespace? string
15
29
  string =~ WHITESPACE_RE
16
30
  end
@@ -311,4 +325,6 @@ module NRSER
311
325
 
312
326
  singleton_class.send :alias_method, :to_const, :constantize
313
327
 
328
+ # @!endgroup String Functions
329
+
314
330
  end # module NRSER