@@ -78,7 +78,7 @@ pipeline to do that like so:
78
78
flowchart LR
79
79
input[String]
80
80
subgraph Pipeline
81
- pipe1[capitalize ]
81
+ pipe1[title ]
82
82
pipe2[trim]
83
83
84
84
pipe1 --> pipe2
@@ -90,14 +90,14 @@ flowchart LR
90
90
```
91
91
92
92
``` python
93
- from pypipeline import Pipeline
93
+ from pypipeline.pipeline import Pipeline
94
94
95
95
# Create a new pipeline instance.
96
96
pipeline = Pipeline()
97
97
98
98
# Send a string through the pipeline.
99
99
result = pipeline.send(' hello world ' ).through([
100
- str .capitalize ,
100
+ str .title ,
101
101
str .strip
102
102
]).then_return()
103
103
@@ -112,7 +112,7 @@ You don't need to build the pipeline all at once, you can spread it out over a n
112
112
flowchart LR
113
113
input[String]
114
114
subgraph Pipeline
115
- pipe1[capitalize ]
115
+ pipe1[title ]
116
116
pipe2[trim]
117
117
pipe3[reverse_string]
118
118
@@ -126,28 +126,25 @@ flowchart LR
126
126
```
127
127
128
128
``` python
129
- from pypipeline import Pipeline
129
+ from pypipeline.pipeline import Pipeline
130
130
131
131
# Create a new pipeline instance.
132
132
pipeline = Pipeline()
133
133
134
134
# Set the pipes you want to use.
135
- pipeline.through([
136
- str .capitalize,
137
- str .strip
138
- ])
135
+ pipeline.through([ str .title, str .strip ])
139
136
140
137
# Add another transformation.
141
- def reverse_string (s ):
142
- return s[:: - 1 ]
138
+ def replace (s ):
139
+ return s.replace( ' Hello ' , ' Goodbye ' )
143
140
144
141
# Add it to the pipeline.
145
- pipeline.pipe(reverse_string )
142
+ pipeline.pipe(replace )
146
143
147
144
# Send data through the pipeline.
148
145
result = pipeline.send(' hello world ' ).then_return()
149
146
150
- print (result) # Output: 'dlrow olleh '
147
+ print (result) # Output: 'Goodbye World '
151
148
```
152
149
153
150
### Using custom pipes
@@ -172,21 +169,19 @@ flowchart LR
172
169
```
173
170
174
171
``` python
175
- from pypipeline import Pipeline
172
+ from pypipeline.pipeline import Pipeline
176
173
177
174
pipeline = Pipeline()
178
175
179
176
def custom_pipe (passable , next_pipe ):
180
177
passable = passable.replace(' hello' , ' goodbye' )
181
178
return next_pipe(passable)
182
179
183
- pipeline.through([
184
- custom_pipe,
185
- str .capitalize
186
- ])
180
+ pipeline.through([custom_pipe, str .title])
187
181
188
182
result = pipeline.send(' hello world' ).then_return()
189
183
print (result) # Output: 'Goodbye world'
184
+
190
185
```
191
186
192
187
### Using classes with the ` handle ` method
@@ -201,9 +196,9 @@ optionally implement the `StellarWP\Pipeline\Contracts\Pipe` interface to enforc
201
196
202
197
First class:
203
198
``` python
204
- class CapitalizePipe :
199
+ class TitlePipe :
205
200
def handle (self , passable , next_pipe ):
206
- return next_pipe(passable.capitalize ())
201
+ return next_pipe(passable.title ())
207
202
```
208
203
209
204
Second class:
@@ -219,7 +214,7 @@ class StripPipe:
219
214
flowchart LR
220
215
input[String]
221
216
subgraph Pipeline
222
- pipe1[CapitalizePipe ::handle]
217
+ pipe1[TitlePipe ::handle]
223
218
pipe2[StripPipe::handle]
224
219
225
220
pipe1 --> pipe2
@@ -231,9 +226,9 @@ flowchart LR
231
226
```
232
227
233
228
``` python
234
- from pypipeline import Pipeline
229
+ from pypipeline.pipeline import Pipeline
235
230
236
- pipeline = Pipeline().through([CapitalizePipe (), StripPipe()])
231
+ pipeline = Pipeline().through([TitlePipe (), StripPipe()])
237
232
result = pipeline.send(' hello world ' ).then_return()
238
233
print (result) # Output: 'Hello world'
239
234
```
@@ -247,9 +242,9 @@ the alternate method name using the `via()` method.
247
242
248
243
First class:
249
244
``` python
250
- class ReversePipe :
245
+ class TitlePipe :
251
246
def execute (self , passable , next_pipe ):
252
- return next_pipe(passable[:: - 1 ] )
247
+ return next_pipe(passable.title() )
253
248
```
254
249
255
250
Second class:
@@ -277,11 +272,11 @@ flowchart LR
277
272
```
278
273
279
274
``` python
280
- from pypipeline import Pipeline
275
+ from pypipeline.pipeline import Pipeline
281
276
282
277
pipeline = Pipeline().via(' execute' ).through([StripPipe(), ReversePipe()])
283
278
result = pipeline.send(' hello ' ).then_return()
284
- print (result) # Output: 'olleh '
279
+ print (result) # Output: 'Hello '
285
280
286
281
```
287
282
@@ -293,7 +288,7 @@ can do this with a `return` statement!
293
288
#### Example pipeline
294
289
295
290
``` python
296
- from pypipeline import Pipeline
291
+ from pypipeline.pipeline import Pipeline
297
292
298
293
def check_content (passable , next_pipe ):
299
294
if ' stop' in passable:
@@ -331,7 +326,7 @@ flowchart LR
331
326
```
332
327
333
328
``` python
334
- from pypipeline import Pipeline
329
+ from pypipeline.pipeline import Pipeline
335
330
336
331
pipeline = Pipeline().through([str .strip, str .upper])
337
332
result = pipeline.send(' hello world ' ).then(lambda x : len (x))
@@ -358,7 +353,7 @@ pipeline.pipe( str.strip )
358
353
# or
359
354
pipeline.add_pipe( str .strip )
360
355
# or
361
- pipeline.pipe( [ str .capitalize , str .strip ] )
356
+ pipeline.pipe( [ str .title , str .strip ] )
362
357
```
363
358
364
359
### ` send() `
@@ -438,16 +433,16 @@ Aliases: `pipes()`
438
433
#### Examples
439
434
``` python
440
435
# You can provide any number of pipes.
441
- pipeline.through([ str .capitalize , str .strip ])
436
+ pipeline.through([ str .title , str .strip ])
442
437
443
438
# Using the alias.
444
- pipeline.pipes([ str .capitalize , str .strip ])
439
+ pipeline.pipes([ str .title , str .strip ])
445
440
446
441
# Pass closures as pipes.
447
- pipeline.through([ str .capitalize , lambda passable , next : next_pipe(passable.strip)])
442
+ pipeline.through([ str .title , lambda passable , next : next_pipe(passable.strip)])
448
443
449
444
# Pass objects as pipes.
450
- pipeline.through([ CapitalizePipe (), StripPipe() ])
445
+ pipeline.through([ TitlePipe (), StripPipe() ])
451
446
```
452
447
453
448
### ` via() `
0 commit comments