Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arcage/pipeline
Line by line text processor for crystal
https://github.com/arcage/pipeline
Last synced: about 2 months ago
JSON representation
Line by line text processor for crystal
- Host: GitHub
- URL: https://github.com/arcage/pipeline
- Owner: arcage
- License: mit
- Created: 2016-12-27T04:53:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-27T14:43:57.000Z (about 8 years ago)
- Last Synced: 2024-10-25T01:36:39.502Z (3 months ago)
- Language: Crystal
- Size: 2.93 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pipeline Command for Crystal
Line by line text processor for console command mainly using with pipes('|').
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
pipeline:
github: arcage/pipeline
```## Usage
Inherit the `Pipeline::Command` class and implement `#proc(line : String)` method on it.
```crystal
# up_case.cr
require "pipeline"class UpCase < Pipeline::Command
def proc(line : String)
line.upcase
endend
UpCase.new.run
``````shell
% crystal up_case.cr
abc def <- INPUT
ABC DEF <- OUTPUT
% cat input.txt
input text file
% crystal up_case.cr -- input.txt
INPUT TEXT FILE
```Default input and ouput are `ARGF` and `STDOUT` respectivery.
You can specify other input or output by calling '#run' method with `input` or `output` argument.
```crystal
File.open("input.txt") do |file|
UpCase.new.run(input: file)
end#output: INPUT TEXT FILE
```Override `#initialize` and call `super(&block)`, then you can set flags for the internal `OptionParser` object in the block.
```crystal
# up_or_camel_case.cr
require "pipeline"class UpOrCamelCase < Pipeline::Command
def initialize
@camelcase = false
super() do
# Default receiver in this block is the internal OpttionParser object.
on("-c", "camel case") { @camelcase = true }
end
enddef proc(line : String) : String
@camelcase ? line.camelcase : line.upcase
endend
UpOrCamelCase.new.run
``````shell
% crystal up_or_camel_case.cr
abc def <- INPUT
ABC DEF <- OUTPUT
^D
% crystal up_or_camel_case.cr -- -c
abc def <- INPUT
AbcDef <- OUTPUT
^D
```## Contributors
- [arcage](https://github.com/arcage) ʕ·ᴥ·ʔAKJ - creator, maintainer