Class: Pipewrench
- Inherits:
-
Object
- Object
- Pipewrench
- Includes:
- Enumerable
- Defined in:
- lib/pipewrench.rb,
lib/pipewrench/options.rb,
lib/pipewrench/version.rb
Defined Under Namespace
Classes: Options
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #evaluate(cmd) ⇒ Object
-
#initialize(stdin, options = Options.new) ⇒ Pipewrench
constructor
A new instance of Pipewrench.
- #run(cmd) ⇒ Object
Constructor Details
#initialize(stdin, options = Options.new) ⇒ Pipewrench
Returns a new instance of Pipewrench.
8 9 10 11 12 13 14 15 16 |
# File 'lib/pipewrench.rb', line 8 def initialize(stdin, =Options.new) @stdin = stdin @options = if .rails require 'active_support' require 'active_support/core_ext' end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/pipewrench.rb', line 5 def @options end |
Instance Method Details
#each(&blk) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/pipewrench.rb', line 34 def each(&blk) if .strip @stdin.each_line.map(&:rstrip).map(&blk) else @stdin.each_line(&blk) end end |
#evaluate(cmd) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/pipewrench.rb', line 26 def evaluate(cmd) if .map map { |line| line.instance_eval(cmd) } else to_a.instance_eval(cmd) end end |
#run(cmd) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/pipewrench.rb', line 18 def run(cmd) if .compact evaluate(cmd).compact else evaluate(cmd) end end |