Class: Frag::App
- Inherits:
-
Object
- Object
- Frag::App
- Defined in:
- lib/frag/app.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(args, input = STDIN, output = STDOUT, error = STDERR) ⇒ App
constructor
A new instance of App.
- #run ⇒ Object
Constructor Details
#initialize(args, input = STDIN, output = STDOUT, error = STDERR) ⇒ App
Returns a new instance of App.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/frag/app.rb', line 7 def initialize(args, input=STDIN, output=STDOUT, error=STDERR) @input, @output, @error = input, output, error @status = 0 beginning = 'GEN:' ending = 'ENDGEN' leader = '#' trailer = '' @backup_prefix = @backup_suffix = nil parser = OptionParser.new do |parser| parser. = "USAGE: #$0 [options] file ..." parser.on '-b', '--begin DELIMITER' do |value| beginning = Regexp.escape(value) end parser.on '-e', '--end DELIMITER' do |value| ending = Regexp.escape(value) end parser.on '-l', '--leader STRING' do |value| leader = Regexp.escape(value) end parser.on '-t', '--trailer STRING' do |value| trailer = Regexp.escape(value) end parser.on '-p', '--backup-prefix PREFIX' do |value| @backup_prefix = value end parser.on '-s', '--backup-suffix SUFFIX' do |value| @backup_suffix = value end end parser.parse!(args) args.size > 0 or return error "no files given" @begin_line = Regexp.new(['^', leader, beginning, '(.*)', trailer, '$'].reject(&:empty?).join('\\s*')) @end_line = Regexp.new(['^', leader, ending, trailer, '$'].reject(&:empty?).join('\\s*')) @input_paths = args end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
59 60 61 |
# File 'lib/frag/app.rb', line 59 def status @status end |
Instance Method Details
#run ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/frag/app.rb', line 49 def run return @status if @status != 0 @input_paths.each do |input_path| manage_files(input_path) do |input, output| process(input, output) end end @status end |