psychgus 1.3.3 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,34 +1,22 @@
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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
-
23
11
  require 'psychgus/stylables'
24
12
 
25
13
  module Psychgus
26
14
  ###
27
15
  # A collection of commonly-used {Styler} classes.
28
- #
16
+ #
29
17
  # @example
30
18
  # require 'psychgus'
31
- #
19
+ #
32
20
  # class EggCarton
33
21
  # def initialize
34
22
  # @eggs = {
@@ -37,9 +25,9 @@ module Psychgus
37
25
  # }
38
26
  # end
39
27
  # end
40
- #
28
+ #
41
29
  # hierarchy = Psychgus::HierarchyStyler.new(io: $stdout)
42
- #
30
+ #
43
31
  # puts EggCarton.new.to_yaml(stylers: [
44
32
  # Psychgus::NoSymStyler.new,
45
33
  # Psychgus::NoTagStyler.new,
@@ -47,13 +35,13 @@ module Psychgus
47
35
  # Psychgus::FlowStyler.new(4),
48
36
  # hierarchy
49
37
  # ])
50
- #
38
+ #
51
39
  # # Output:
52
40
  # # ---
53
41
  # # Eggs:
54
42
  # # Styles: [Fried, Scrambled, [BBQ, Ketchup & Mustard]]
55
43
  # # Colors: [Brown, White, [Blue, Green]]
56
- #
44
+ #
57
45
  # # (1:1):Psych::Nodes::Stream - <root:(0:0)>
58
46
  # # (1:1):Psych::Nodes::Document - <stream:(1:1)>
59
47
  # # (1:1):Psych::Nodes::Mapping - <doc:(1:1)>
@@ -73,20 +61,17 @@ module Psychgus
73
61
  # # (6:3):Psych::Nodes::Sequence - <seq:(5:1)>
74
62
  # # (7:1):Blue - <seq:(6:3)>
75
63
  # # (7:2):Green - <seq:(6:3)>
76
- #
77
- # @author Jonathan Bradley Whited (@esotericpig)
78
- # @since 1.2.0
79
- #
64
+ #
80
65
  # @see Stylables
81
66
  # @see Styler
82
67
  ###
83
68
  module Stylers
84
69
  ###
85
70
  # A Capitalizer for Scalars.
86
- #
71
+ #
87
72
  # @example
88
73
  # require 'psychgus'
89
- #
74
+ #
90
75
  # data = {
91
76
  # 'eggs' => [
92
77
  # 'omelette',
@@ -95,78 +80,78 @@ module Psychgus
95
80
  # 'soft_boiled eggs',
96
81
  # 'fried@eggs'
97
82
  # ]}
98
- #
83
+ #
99
84
  # seq_flow = Psychgus::SeqFlowStyler.new
100
- #
85
+ #
101
86
  # puts data.to_yaml(stylers: [Psychgus::CapStyler.new,seq_flow])
102
- #
87
+ #
103
88
  # # Output:
104
89
  # # ---
105
90
  # # Eggs: [Omelette, BBQ Eggs, Hard-Boiled Eggs, Soft_Boiled Eggs, Fried@eggs]
106
- #
91
+ #
107
92
  # puts data.to_yaml(stylers: [Psychgus::CapStyler.new(each_word: false),seq_flow])
108
- #
93
+ #
109
94
  # # Output:
110
95
  # # ---
111
96
  # # Eggs: [Omelette, BBQ eggs, Hard-boiled eggs, Soft_boiled eggs, Fried@eggs]
112
- #
97
+ #
113
98
  # puts data.to_yaml(stylers: [Psychgus::CapStyler.new(new_delim: '(o)'),seq_flow])
114
- #
99
+ #
115
100
  # # Output:
116
101
  # # ---
117
102
  # # Eggs: [Omelette, BBQ(o)Eggs, Hard(o)Boiled(o)Eggs, Soft(o)Boiled(o)Eggs, Fried@eggs]
118
- #
103
+ #
119
104
  # class Cappie
120
105
  # include Psychgus::CapStylable
121
- #
106
+ #
122
107
  # def cap_word(word)
123
108
  # return 'bbq' if word.casecmp('BBQ') == 0
124
- #
109
+ #
125
110
  # super(word)
126
111
  # end
127
112
  # end
128
- #
113
+ #
129
114
  # puts data.to_yaml(stylers: [Cappie.new(new_delim: '*',delim: /[\s@]/),seq_flow])
130
- #
115
+ #
131
116
  # # Output:
132
117
  # # ---
133
118
  # # Eggs: [Omelette, bbq*Eggs, Hard-boiled*Eggs, Soft_boiled*Eggs, Fried*Eggs]
134
- #
119
+ #
135
120
  # @see Stylables::CapStylable
136
121
  ###
137
122
  class CapStyler
138
123
  include Stylables::CapStylable
139
124
  end
140
-
125
+
141
126
  ###
142
127
  # A FLOW style changer for Mappings & Sequences.
143
- #
128
+ #
144
129
  # @example
145
130
  # require 'psychgus'
146
- #
131
+ #
147
132
  # data = {
148
133
  # 'Eggs' => {
149
134
  # 'Styles' => ['Fried', 'Scrambled', ['BBQ', 'Ketchup']],
150
135
  # 'Colors' => ['Brown', 'White', ['Blue', 'Green']]
151
136
  # }}
152
- #
137
+ #
153
138
  # puts data.to_yaml(stylers: Psychgus::FlowStyler.new)
154
- #
139
+ #
155
140
  # # Output:
156
141
  # # --- {Eggs: {Styles: [Fried, Scrambled, [BBQ, Ketchup]], Colors: [Brown, White, [Blue, Green]]}}
157
- #
142
+ #
158
143
  # # >= level 4 (see Psychgus.hierarchy)
159
144
  # puts data.to_yaml(stylers: Psychgus::FlowStyler.new(4))
160
- #
145
+ #
161
146
  # # Output:
162
147
  # # ---
163
148
  # # Eggs:
164
149
  # # Styles: [Fried, Scrambled, [BBQ, Ketchup]]
165
150
  # # Colors: [Brown, White, [Blue, Green]]
166
- #
151
+ #
167
152
  # # >= level 6 (see Psychgus.hierarchy)
168
153
  # puts data.to_yaml(stylers: Psychgus::FlowStyler.new(6))
169
- #
154
+ #
170
155
  # # Output:
171
156
  # # ---
172
157
  # # Eggs:
@@ -178,7 +163,7 @@ module Psychgus
178
163
  # # - Brown
179
164
  # # - White
180
165
  # # - [Blue, Green]
181
- #
166
+ #
182
167
  # @see Stylables::MapFlowStylable
183
168
  # @see Stylables::SeqFlowStylable
184
169
  ###
@@ -186,118 +171,118 @@ module Psychgus
186
171
  include Stylables::MapFlowStylable
187
172
  include Stylables::SeqFlowStylable
188
173
  end
189
-
174
+
190
175
  ###
191
176
  # A visual hierarchy writer of the levels.
192
- #
177
+ #
193
178
  # This is useful for determining the correct level/position when writing a {Styler}.
194
- #
179
+ #
195
180
  # The default IO is StringIO, but can specify a different one.
196
- #
181
+ #
197
182
  # See {Psychgus.hierarchy} for more details.
198
- #
183
+ #
199
184
  # @see Psychgus.hierarchy
200
185
  # @see Stylables::HierarchyStylable
201
186
  ###
202
187
  class HierarchyStyler
203
188
  include Stylables::HierarchyStylable
204
189
  end
205
-
190
+
206
191
  ###
207
192
  # A FLOW style changer for Mappings only.
208
- #
193
+ #
209
194
  # @see FlowStyler
210
195
  # @see Stylables::MapFlowStylable
211
196
  ###
212
197
  class MapFlowStyler
213
198
  include Stylables::MapFlowStylable
214
199
  end
215
-
200
+
216
201
  ###
217
202
  # A Symbol remover for Scalars.
218
- #
203
+ #
219
204
  # @example
220
205
  # require 'psychgus'
221
- #
206
+ #
222
207
  # data = {
223
208
  # :eggs => {
224
209
  # :styles => ['Fried', 'Scrambled', ['BBQ', 'Ketchup']],
225
210
  # :colors => ['Brown', 'White', ['Blue', 'Green']]
226
211
  # }}
227
- #
212
+ #
228
213
  # flow = Psychgus::FlowStyler.new(4)
229
- #
214
+ #
230
215
  # puts data.to_yaml(stylers: [Psychgus::NoSymStyler.new,flow])
231
- #
216
+ #
232
217
  # # Output:
233
218
  # # ---
234
219
  # # Eggs:
235
220
  # # Styles: [Fried, Scrambled, [BBQ, Ketchup]]
236
221
  # # Colors: [Brown, White, [Blue, Green]]
237
- #
222
+ #
238
223
  # puts data.to_yaml(stylers: [Psychgus::NoSymStyler.new(cap: false),flow])
239
- #
224
+ #
240
225
  # # ---
241
226
  # # eggs:
242
227
  # # styles: [Fried, Scrambled, [BBQ, Ketchup]]
243
228
  # # colors: [Brown, White, [Blue, Green]]
244
- #
229
+ #
245
230
  # @see Stylables::NoSymStylable
246
231
  ###
247
232
  class NoSymStyler
248
233
  include Stylables::NoSymStylable
249
234
  end
250
-
235
+
251
236
  ###
252
237
  # A Tag remover for classes.
253
- #
238
+ #
254
239
  # @example
255
240
  # require 'psychgus'
256
- #
241
+ #
257
242
  # class Eggs
258
243
  # def initialize
259
244
  # @styles = ['Fried', 'Scrambled', ['BBQ', 'Ketchup']]
260
245
  # @colors = ['Brown', 'White', ['Blue', 'Green']]
261
246
  # end
262
247
  # end
263
- #
248
+ #
264
249
  # class EggCarton
265
250
  # include Psychgus::Blueberry
266
- #
251
+ #
267
252
  # def initialize
268
253
  # @eggs = Eggs.new
269
254
  # end
270
- #
255
+ #
271
256
  # def psychgus_stylers(sniffer)
272
257
  # Psychgus::FlowStyler.new(4)
273
258
  # end
274
259
  # end
275
- #
260
+ #
276
261
  # puts EggCarton.new.to_yaml
277
- #
262
+ #
278
263
  # # Output:
279
264
  # # --- !ruby/object:EggCarton
280
265
  # # eggs: !ruby/object:Eggs
281
266
  # # styles: [Fried, Scrambled, [BBQ, Ketchup]]
282
267
  # # colors: [Brown, White, [Blue, Green]]
283
- #
268
+ #
284
269
  # puts EggCarton.new.to_yaml(stylers: Psychgus::NoTagStyler.new)
285
- #
270
+ #
286
271
  # # Output:
287
272
  # # ---
288
273
  # # eggs:
289
274
  # # styles: [Fried, Scrambled, [BBQ, Ketchup]]
290
275
  # # colors: [Brown, White, [Blue, Green]]
291
- #
276
+ #
292
277
  # @see Stylables::NoTagStylable
293
278
  ###
294
279
  class NoTagStyler
295
280
  include Stylables::NoTagStylable
296
281
  end
297
-
282
+
298
283
  ###
299
284
  # A FLOW style changer for Sequences only.
300
- #
285
+ #
301
286
  # @see FlowStyler
302
287
  # @see Stylables::SeqFlowStylable
303
288
  ###
@@ -1,80 +1,66 @@
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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
20
9
  #++
21
10
 
22
-
23
11
  require 'delegate'
24
12
 
25
-
26
13
  module Psychgus
27
14
  class SuperSniffer
28
15
  ###
29
16
  # A container for the parent of a Psych::Nodes::Node.
30
- #
17
+ #
31
18
  # A parent is a Mapping, Sequence, or a Key (Scalar) of a Mapping.
32
- #
19
+ #
33
20
  # You can use the getters in this class in {Styler} to filter what to change.
34
- #
21
+ #
35
22
  # If a Node method has not been exposed, you can use {#node}:
36
23
  # if parent.node_of?(:scalar)
37
24
  # parent.value = 'FUBAR'
38
25
  # parent.node.value = 'FUBAR' # Same as above
39
- #
26
+ #
40
27
  # parent.fubar = true # NoMethodError
41
28
  # parent.node.fubar = true # Use some new Psych::Nodes::Node method not in this version
42
29
  # # of Psychgus or that is not exposed by Parent
43
30
  # end
44
- #
45
- # @author Jonathan Bradley Whited (@esotericpig)
46
- # @since 1.0.0
47
- #
31
+ #
48
32
  # @see SuperSniffer
49
33
  # @see SuperSniffer#start_parent SuperSniffer#start_parent
50
34
  # @see SuperSniffer#end_parent SuperSniffer#end_parent
51
35
  # @see Styler
52
36
  ###
53
- class Parent < Delegator
37
+ class Parent < SimpleDelegator
54
38
  # Calling the getter is fine; calling the setter is *not* and could cause weird results.
55
- #
39
+ #
56
40
  # @return [Integer] the next child's position
57
41
  attr_accessor :child_position
58
-
42
+
59
43
  # Calling the getter is fine; calling the setter is *not* and could cause weird results.
60
- #
44
+ #
61
45
  # @return [nil,:key,:value] the next child's Mapping type, if {#node} is a Mapping
62
46
  attr_accessor :child_type
63
-
47
+
64
48
  # @return [:noface,Symbol,String] a tag (class name, value) for debugging; also used in {#to_s}
65
49
  attr_reader :debug_tag
66
-
50
+
67
51
  attr_reader :level # @return [Integer] the level of this Node in the YAML
68
52
  attr_reader :node # @return [Psych::Nodes::Node] the Node of this parent
69
53
  attr_reader :position # @return [Integer] the position of this Node in the YAML
70
-
54
+
71
55
  # Initialize this class with parent data.
72
- #
56
+ #
73
57
  # @param sniffer [SuperSniffer] the sniffer that contains this parent (not stored; used for data)
74
58
  # @param node [Psych::Nodes::Node] the node of this parent
75
59
  # @param debug_tag [:noface,Symbol,String] the tag (class name, value) used for debugging and in {#to_s}
76
60
  # @param child_type [nil,:key,:value] the next child's Mapping type, if +node+ is a Mapping
77
61
  def initialize(sniffer,node,debug_tag: nil,child_type: nil)
62
+ super(node)
63
+
78
64
  @child_position = 1
79
65
  @child_type = child_type
80
66
  @debug_tag = debug_tag
@@ -82,61 +68,57 @@ module Psychgus
82
68
  @node = node
83
69
  @position = sniffer.position
84
70
  end
85
-
71
+
86
72
  # @api private
87
73
  def __getobj__
88
74
  return @node
89
75
  end
90
-
76
+
91
77
  # Check if the children of this parent are keys to a Mapping.
92
- #
78
+ #
93
79
  # @return [true,false] whether the children are keys to a Mapping
94
- #
95
- # @since 1.2.0
96
- def child_key?()
80
+ def child_key?
97
81
  return @child_type == :key
98
82
  end
99
-
83
+
100
84
  # Check if the children of this parent are values to a Mapping (i.e., values to a key).
101
- #
85
+ #
102
86
  # @return [true,false] whether the children are values to a Mapping (i.e., values to a key)
103
- #
104
- # @since 1.2.0
105
- def child_value?()
87
+ def child_value?
106
88
  return @child_type == :value
107
89
  end
108
-
90
+
109
91
  # @see Psych::Nodes::Document#implicit
110
92
  # @see Psych::Nodes::Mapping#implicit
111
93
  # @see Psych::Nodes::Sequence#implicit
112
- def implicit?()
94
+ def implicit?
113
95
  return @node.implicit
114
96
  end
115
-
97
+
116
98
  # @see Psych::Nodes::Document#implicit_end
117
- def implicit_end?()
99
+ def implicit_end?
118
100
  return @node.implicit_end
119
101
  end
120
-
102
+
121
103
  # (see Ext::NodeExt#node_of?)
122
104
  def node_of?(*names)
123
105
  return @node.node_of?(*names)
124
106
  end
125
-
107
+
126
108
  # @see Psych::Nodes::Scalar#plain
127
- def plain?()
109
+ def plain?
128
110
  return @node.plain
129
111
  end
130
-
112
+
131
113
  # @see Psych::Nodes::Scalar#quoted
132
- def quoted?()
114
+ def quoted?
133
115
  return @node.quoted
134
116
  end
135
-
117
+
136
118
  # @note If this method is modified, then tests will fail
137
- #
119
+ #
138
120
  # @return [String] a String representation of this class for debugging and testing
139
- def to_s()
121
+ def to_s
140
122
  return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>"
141
123
  end
142
124
  end