Class: Frag::App

Inherits:
Object
  • Object
show all
Defined in:
lib/frag/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, input = STDIN, output = STDOUT, error = STDERR) ⇒ App

Returns a new instance of App.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/frag/app.rb', line 8

def initialize(args, input=STDIN, output=STDOUT, error=STDERR)
  @input, @output, @error = input, output, error
  @status = 0
  @version_printed = false

  @state = State.new('frag:', 'frag end', '#', '', nil, nil)

  begin
    parser.parse!(args)
  rescue OptionParser::InvalidOption => e
    return error e.message
  end
  args.size > 0 || @version_printed or
    return error "no files given"

  @input_paths = args
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



38
39
40
# File 'lib/frag/app.rb', line 38

def status
  @status
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/frag/app.rb', line 26

def run
  return @status if @status != 0
  global_state = @state.dup
  @input_paths.each do |input_path|
    @state = global_state.dup
    manage_files(input_path) do |input, output|
      process(input, output)
    end
  end
  @status
end