Class: Deanswerify::Exec
- Inherits:
-
Object
- Object
- Deanswerify::Exec
- Defined in:
- lib/deanswerify.rb
Overview
Kicks off the parsing process by parsing command-line arguments and calling the method that parses each input file.
Instance Method Summary collapse
-
#initialize(args) ⇒ Exec
constructor
A new instance of Exec.
-
#parse ⇒ Object
Parses the command-line arguments and begins parsing the files.
-
#parse! ⇒ Object
Parses the command-line arguments and begins parsing the files.
-
#process_result ⇒ Object
Processes the input files, removing all answer blocks.
-
#set_opts(opts) ⇒ Object
Takes the command-line arguments and parses them for optparse.
Constructor Details
#initialize(args) ⇒ Exec
Returns a new instance of Exec.
10 11 12 13 |
# File 'lib/deanswerify.rb', line 10 def initialize(args) @args = args = {} end |
Instance Method Details
#parse ⇒ Object
Parses the command-line arguments and begins parsing the files.
26 27 28 29 30 31 |
# File 'lib/deanswerify.rb', line 26 def parse @opts = OptionParser.new(&method(:set_opts)) @opts.parse!(@args) process_result end |
#parse! ⇒ Object
Parses the command-line arguments and begins parsing the files.
18 19 20 21 |
# File 'lib/deanswerify.rb', line 18 def parse! parse exit 0 end |
#process_result ⇒ Object
Processes the input files, removing all answer blocks
71 72 73 74 75 76 77 |
# File 'lib/deanswerify.rb', line 71 def process_result # Get a list of filenames to parse, and ignore the .git folder files = %x(find #{@options[:directory]} -type f -not -iwholename '*.git*').split("\n") # Parse each file in the filenames array Deanswerify::Parser.parse_files files end |
#set_opts(opts) ⇒ Object
Takes the command-line arguments and parses them for optparse.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/deanswerify.rb', line 36 def set_opts(opts) opts. = "deanswerify v\#{Deanswerify::VERSION}\n\nDescription:\n\nParses every file within your current git tree, recursing into\nsubdirectories and laying waste to any text between the following delimiters:\n\n I won't be deleted\n /* SOLUTION */\n Text to be deleted\n Multiline is okay\n /* END SOLUTION */\n Case doesn't matter, and you can do /* solution */ inline /* end solution */\n\nUsage (from within a .git repository):\n\n deanswerify [options]\n\nOptions:\n" # Set default options [:directory] = `git rev-parse --show-toplevel`.delete("\n") # opts.on( '-d', '--directory', 'Parse a particular directory' ) do # end opts.on_tail( '-h', '--help', 'Display this screen' ) do puts opts exit end end |