psychgus 1.2.0 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  #--
5
5
  # This file is part of Psychgus.
6
- # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # Psychgus is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2019-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
11
 
@@ -26,47 +15,47 @@ module Psychgus
26
15
  module Styler
27
16
  ###
28
17
  # An empty {Styler} as a class.
29
- #
30
- # @author Jonathan Bradley Whited (@esotericpig)
18
+ #
19
+ # @author Jonathan Bradley Whited
31
20
  # @since 1.0.0
32
21
  ###
33
22
  class Empty
34
23
  include Styler
35
24
  end
36
25
  end
37
-
26
+
38
27
  ###
39
28
  # Mix in (include) this module to make a class/module/etc. a styler for YAML.
40
- #
29
+ #
41
30
  # Although it's unnecessary (because of Duck Typing), it's the recommended practice in case a new method is
42
31
  # added in the future, and also so you don't have to define methods that you don't use.
43
- #
32
+ #
44
33
  # You can either use this as is (see example) or inside of a class (see {Blueberry}).
45
- #
34
+ #
46
35
  # @example
47
36
  # class MyStyler
48
37
  # include Psychgus::Styler
49
- #
38
+ #
50
39
  # def style_sequence(sniffer,node)
51
40
  # node.style = Psychgus::SEQUENCE_FLOW if sniffer.level == 3
52
41
  # end
53
42
  # end
54
- #
43
+ #
55
44
  # hash = {'Coffee'=>{
56
45
  # 'Roast'=>['Light','Medium','Dark','Extra Dark'],
57
46
  # 'Style'=>['Cappuccino','Espresso','Latte','Mocha']
58
47
  # }}
59
48
  # puts hash.to_yaml(stylers: MyStyler.new())
60
- #
49
+ #
61
50
  # # Output:
62
51
  # # ---
63
52
  # # Coffee:
64
53
  # # Roast: [Light, Medium, Dark, Extra Dark]
65
54
  # # Style: [Cappuccino, Espresso, Latte, Mocha]
66
- #
67
- # @author Jonathan Bradley Whited (@esotericpig)
55
+ #
56
+ # @author Jonathan Bradley Whited
68
57
  # @since 1.0.0
69
- #
58
+ #
70
59
  # @see Psychgus
71
60
  # @see Ext::ObjectExt#to_yaml
72
61
  # @see Blueberry
@@ -75,51 +64,51 @@ module Psychgus
75
64
  # @see Ext::YAMLTreeExt#accept
76
65
  ###
77
66
  module Styler
78
- EMPTY = Empty.new().freeze()
79
-
67
+ EMPTY = Empty.new.freeze
68
+
80
69
  # Style a node of any type.
81
- #
70
+ #
82
71
  # You can use {Ext::NodeExt#node_of?} to determine its type:
83
72
  # puts node.value if node.node_of?(:scalar)
84
- #
73
+ #
85
74
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
86
75
  # @param node [Psych::Nodes::Node] passed in from {StyledTreeBuilder}
87
- #
76
+ #
88
77
  # @see Ext::NodeExt#node_of?
89
78
  def style(sniffer,node) end
90
-
79
+
91
80
  # Style a node guaranteed to be of type Psych::Nodes::Alias, to avoid if statements.
92
- #
81
+ #
93
82
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
94
83
  # @param node [Psych::Nodes::Alias] of type Alias passed in from {StyledTreeBuilder}
95
84
  def style_alias(sniffer,node) end
96
-
85
+
97
86
  # Style a node guaranteed to be of type Psych::Nodes::Document, to avoid if statements.
98
- #
87
+ #
99
88
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
100
89
  # @param node [Psych::Nodes::Document] of type Document passed in from {StyledTreeBuilder}
101
90
  def style_document(sniffer,node) end
102
-
91
+
103
92
  # Style a node guaranteed to be of type Psych::Nodes::Mapping, to avoid if statements.
104
- #
93
+ #
105
94
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
106
95
  # @param node [Psych::Nodes::Mapping] of type Mapping passed in from {StyledTreeBuilder}
107
96
  def style_mapping(sniffer,node) end
108
-
97
+
109
98
  # Style a node guaranteed to be of type Psych::Nodes::Scalar, to avoid if statements.
110
- #
99
+ #
111
100
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
112
101
  # @param node [Psych::Nodes::Scalar] of type Scalar passed in from {StyledTreeBuilder}
113
102
  def style_scalar(sniffer,node) end
114
-
103
+
115
104
  # Style a node guaranteed to be of type Psych::Nodes::Sequence, to avoid if statements.
116
- #
105
+ #
117
106
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
118
107
  # @param node [Psych::Nodes::Sequence] of type Sequence passed in from {StyledTreeBuilder}
119
108
  def style_sequence(sniffer,node) end
120
-
109
+
121
110
  # Style a node guaranteed to be of type Psych::Nodes::Stream, to avoid if statements.
122
- #
111
+ #
123
112
  # @param sniffer [SuperSniffer] passed in from {StyledTreeBuilder}
124
113
  # @param node [Psych::Nodes::Stream] of type Stream passed in from {StyledTreeBuilder}
125
114
  def style_stream(sniffer,node) end
@@ -1,22 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  #--
5
5
  # This file is part of Psychgus.
6
- # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # Psychgus is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # Psychgus is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with Psychgus. If not, see <http://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2019-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
11
 
@@ -25,10 +14,10 @@ require 'psychgus/stylables'
25
14
  module Psychgus
26
15
  ###
27
16
  # A collection of commonly-used {Styler} classes.
28
- #
17
+ #
29
18
  # @example
30
19
  # require 'psychgus'
31
- #
20
+ #
32
21
  # class EggCarton
33
22
  # def initialize
34
23
  # @eggs = {
@@ -37,9 +26,9 @@ module Psychgus
37
26
  # }
38
27
  # end
39
28
  # end
40
- #
29
+ #
41
30
  # hierarchy = Psychgus::HierarchyStyler.new(io: $stdout)
42
- #
31
+ #
43
32
  # puts EggCarton.new.to_yaml(stylers: [
44
33
  # Psychgus::NoSymStyler.new,
45
34
  # Psychgus::NoTagStyler.new,
@@ -47,13 +36,13 @@ module Psychgus
47
36
  # Psychgus::FlowStyler.new(4),
48
37
  # hierarchy
49
38
  # ])
50
- #
39
+ #
51
40
  # # Output:
52
41
  # # ---
53
42
  # # Eggs:
54
43
  # # Styles: [Fried, Scrambled, [BBQ, Ketchup & Mustard]]
55
44
  # # Colors: [Brown, White, [Blue, Green]]
56
- #
45
+ #
57
46
  # # (1:1):Psych::Nodes::Stream - <root:(0:0)>
58
47
  # # (1:1):Psych::Nodes::Document - <stream:(1:1)>
59
48
  # # (1:1):Psych::Nodes::Mapping - <doc:(1:1)>
@@ -73,20 +62,20 @@ module Psychgus
73
62
  # # (6:3):Psych::Nodes::Sequence - <seq:(5:1)>
74
63
  # # (7:1):Blue - <seq:(6:3)>
75
64
  # # (7:2):Green - <seq:(6:3)>
76
- #
77
- # @author Jonathan Bradley Whited (@esotericpig)
65
+ #
66
+ # @author Jonathan Bradley Whited
78
67
  # @since 1.2.0
79
- #
68
+ #
80
69
  # @see Stylables
81
70
  # @see Styler
82
71
  ###
83
72
  module Stylers
84
73
  ###
85
74
  # A Capitalizer for Scalars.
86
- #
75
+ #
87
76
  # @example
88
77
  # require 'psychgus'
89
- #
78
+ #
90
79
  # data = {
91
80
  # 'eggs' => [
92
81
  # 'omelette',
@@ -95,78 +84,78 @@ module Psychgus
95
84
  # 'soft_boiled eggs',
96
85
  # 'fried@eggs'
97
86
  # ]}
98
- #
87
+ #
99
88
  # seq_flow = Psychgus::SeqFlowStyler.new
100
- #
89
+ #
101
90
  # puts data.to_yaml(stylers: [Psychgus::CapStyler.new,seq_flow])
102
- #
91
+ #
103
92
  # # Output:
104
93
  # # ---
105
94
  # # Eggs: [Omelette, BBQ Eggs, Hard-Boiled Eggs, Soft_Boiled Eggs, Fried@eggs]
106
- #
95
+ #
107
96
  # puts data.to_yaml(stylers: [Psychgus::CapStyler.new(each_word: false),seq_flow])
108
- #
97
+ #
109
98
  # # Output:
110
99
  # # ---
111
100
  # # Eggs: [Omelette, BBQ eggs, Hard-boiled eggs, Soft_boiled eggs, Fried@eggs]
112
- #
101
+ #
113
102
  # puts data.to_yaml(stylers: [Psychgus::CapStyler.new(new_delim: '(o)'),seq_flow])
114
- #
103
+ #
115
104
  # # Output:
116
105
  # # ---
117
106
  # # Eggs: [Omelette, BBQ(o)Eggs, Hard(o)Boiled(o)Eggs, Soft(o)Boiled(o)Eggs, Fried@eggs]
118
- #
107
+ #
119
108
  # class Cappie
120
109
  # include Psychgus::CapStylable
121
- #
110
+ #
122
111
  # def cap_word(word)
123
112
  # return 'bbq' if word.casecmp('BBQ') == 0
124
- #
113
+ #
125
114
  # super(word)
126
115
  # end
127
116
  # end
128
- #
117
+ #
129
118
  # puts data.to_yaml(stylers: [Cappie.new(new_delim: '*',delim: /[\s@]/),seq_flow])
130
- #
119
+ #
131
120
  # # Output:
132
121
  # # ---
133
122
  # # Eggs: [Omelette, bbq*Eggs, Hard-boiled*Eggs, Soft_boiled*Eggs, Fried*Eggs]
134
- #
123
+ #
135
124
  # @see Stylables::CapStylable
136
125
  ###
137
126
  class CapStyler
138
127
  include Stylables::CapStylable
139
128
  end
140
-
129
+
141
130
  ###
142
131
  # A FLOW style changer for Mappings & Sequences.
143
- #
132
+ #
144
133
  # @example
145
134
  # require 'psychgus'
146
- #
135
+ #
147
136
  # data = {
148
137
  # 'Eggs' => {
149
138
  # 'Styles' => ['Fried', 'Scrambled', ['BBQ', 'Ketchup']],
150
139
  # 'Colors' => ['Brown', 'White', ['Blue', 'Green']]
151
140
  # }}
152
- #
141
+ #
153
142
  # puts data.to_yaml(stylers: Psychgus::FlowStyler.new)
154
- #
143
+ #
155
144
  # # Output:
156
145
  # # --- {Eggs: {Styles: [Fried, Scrambled, [BBQ, Ketchup]], Colors: [Brown, White, [Blue, Green]]}}
157
- #
146
+ #
158
147
  # # >= level 4 (see Psychgus.hierarchy)
159
148
  # puts data.to_yaml(stylers: Psychgus::FlowStyler.new(4))
160
- #
149
+ #
161
150
  # # Output:
162
151
  # # ---
163
152
  # # Eggs:
164
153
  # # Styles: [Fried, Scrambled, [BBQ, Ketchup]]
165
154
  # # Colors: [Brown, White, [Blue, Green]]
166
- #
155
+ #
167
156
  # # >= level 6 (see Psychgus.hierarchy)
168
157
  # puts data.to_yaml(stylers: Psychgus::FlowStyler.new(6))
169
- #
158
+ #
170
159
  # # Output:
171
160
  # # ---
172
161
  # # Eggs:
@@ -178,7 +167,7 @@ module Psychgus
178
167
  # # - Brown
179
168
  # # - White
180
169
  # # - [Blue, Green]
181
- #
170
+ #
182
171
  # @see Stylables::MapFlowStylable
183
172
  # @see Stylables::SeqFlowStylable
184
173
  ###
@@ -186,118 +175,118 @@ module Psychgus
186
175
  include Stylables::MapFlowStylable
187
176
  include Stylables::SeqFlowStylable
188
177
  end
189
-
178
+
190
179
  ###
191
180
  # A visual hierarchy writer of the levels.
192
- #
181
+ #
193
182
  # This is useful for determining the correct level/position when writing a {Styler}.
194
- #
183
+ #
195
184
  # The default IO is StringIO, but can specify a different one.
196
- #
185
+ #
197
186
  # See {Psychgus.hierarchy} for more details.
198
- #
187
+ #
199
188
  # @see Psychgus.hierarchy
200
189
  # @see Stylables::HierarchyStylable
201
190
  ###
202
191
  class HierarchyStyler
203
192
  include Stylables::HierarchyStylable
204
193
  end
205
-
194
+
206
195
  ###
207
196
  # A FLOW style changer for Mappings only.
208
- #
197
+ #
209
198
  # @see FlowStyler
210
199
  # @see Stylables::MapFlowStylable
211
200
  ###
212
201
  class MapFlowStyler
213
202
  include Stylables::MapFlowStylable
214
203
  end
215
-
204
+
216
205
  ###
217
206
  # A Symbol remover for Scalars.
218
- #
207
+ #
219
208
  # @example
220
209
  # require 'psychgus'
221
- #
210
+ #
222
211
  # data = {
223
212
  # :eggs => {
224
213
  # :styles => ['Fried', 'Scrambled', ['BBQ', 'Ketchup']],
225
214
  # :colors => ['Brown', 'White', ['Blue', 'Green']]
226
215
  # }}
227
- #
216
+ #
228
217
  # flow = Psychgus::FlowStyler.new(4)
229
- #
218
+ #
230
219
  # puts data.to_yaml(stylers: [Psychgus::NoSymStyler.new,flow])
231
- #
220
+ #
232
221
  # # Output:
233
222
  # # ---
234
223
  # # Eggs:
235
224
  # # Styles: [Fried, Scrambled, [BBQ, Ketchup]]
236
225
  # # Colors: [Brown, White, [Blue, Green]]
237
- #
226
+ #
238
227
  # puts data.to_yaml(stylers: [Psychgus::NoSymStyler.new(cap: false),flow])
239
- #
228
+ #
240
229
  # # ---
241
230
  # # eggs:
242
231
  # # styles: [Fried, Scrambled, [BBQ, Ketchup]]
243
232
  # # colors: [Brown, White, [Blue, Green]]
244
- #
233
+ #
245
234
  # @see Stylables::NoSymStylable
246
235
  ###
247
236
  class NoSymStyler
248
237
  include Stylables::NoSymStylable
249
238
  end
250
-
239
+
251
240
  ###
252
241
  # A Tag remover for classes.
253
- #
242
+ #
254
243
  # @example
255
244
  # require 'psychgus'
256
- #
245
+ #
257
246
  # class Eggs
258
247
  # def initialize
259
248
  # @styles = ['Fried', 'Scrambled', ['BBQ', 'Ketchup']]
260
249
  # @colors = ['Brown', 'White', ['Blue', 'Green']]
261
250
  # end
262
251
  # end
263
- #
252
+ #
264
253
  # class EggCarton
265
254
  # include Psychgus::Blueberry
266
- #
255
+ #
267
256
  # def initialize
268
257
  # @eggs = Eggs.new
269
258
  # end
270
- #
259
+ #
271
260
  # def psychgus_stylers(sniffer)
272
261
  # Psychgus::FlowStyler.new(4)
273
262
  # end
274
263
  # end
275
- #
264
+ #
276
265
  # puts EggCarton.new.to_yaml
277
- #
266
+ #
278
267
  # # Output:
279
268
  # # --- !ruby/object:EggCarton
280
269
  # # eggs: !ruby/object:Eggs
281
270
  # # styles: [Fried, Scrambled, [BBQ, Ketchup]]
282
271
  # # colors: [Brown, White, [Blue, Green]]
283
- #
272
+ #
284
273
  # puts EggCarton.new.to_yaml(stylers: Psychgus::NoTagStyler.new)
285
- #
274
+ #
286
275
  # # Output:
287
276
  # # ---
288
277
  # # eggs:
289
278
  # # styles: [Fried, Scrambled, [BBQ, Ketchup]]
290
279
  # # colors: [Brown, White, [Blue, Green]]
291
- #
280
+ #
292
281
  # @see Stylables::NoTagStylable
293
282
  ###
294
283
  class NoTagStyler
295
284
  include Stylables::NoTagStylable
296
285
  end
297
-
286
+
298
287
  ###
299
288
  # A FLOW style changer for Sequences only.
300
- #
289
+ #
301
290
  # @see FlowStyler
302
291
  # @see Stylables::SeqFlowStylable
303
292
  ###