tbrooke
7/15/2014 - 3:23 PM

Simple Command Line Parser in Ruby

Simple Command Line Parser in Ruby

###  Spec file for Parse

require 'rspec'
require 'parse'

describe Parse do 

  it 'reads a file as input from the comand line' do

  end

end
#!~/school/env ruby

## Simple Parser read in a file from the command line and spit it back out like cat
## Loosely based on Gregory Brown's article on Command line Utilities


class Reader

  ## This reads in the file on the Command line 

  def Initialize(arg)

    @params, @args = parse_options(argv)
    @display        = Par::Display.new(@params)
  end


  def run
    if @files.empty?
      @display.render(STDIN)
    else
      @files.each do |filename|
        File.open(filename) { |f| @display.render(f) }
      end
    end
  end


  def parse_options(argv)
    # ignore this for now
  end


end


class Parser

 # This is simple parsing of the file 

end
## Gemfile Mainly for Specs

gem 'rspec', github: 'rspec/rspec'
gem 'rspec-core', github: 'rspec/rspec-core'
gem 'rspec-mocks', github: 'rspec/rspec-mocks'
gem 'rspec-expectations', github: 'rspec/rspec-expectations'
gem 'rspec-support', github: 'rspec/rspec-support'