Class: Stamina::Command::RedBlueCommand
- Inherits:
-
StaminaCommand
- Object
- StaminaCommand
- Stamina::Command::RedBlueCommand
- Defined in:
- lib/stamina/command/redblue_command.rb
Overview
Implementation of the redblue command line tool
Instance Attribute Summary
Attributes inherited from StaminaCommand
Instance Method Summary collapse
-
#initialize ⇒ RedBlueCommand
constructor
Creates a score command instance.
-
#main(argv) ⇒ Object
Executes the command.
-
#options ⇒ Object
Installs additional options.
-
#sample_file=(file) ⇒ Object
Sets the sample file.
Methods inherited from StaminaCommand
#assert_readable_file, #assert_writable_file, #parse, #show_usage
Constructor Details
#initialize ⇒ RedBlueCommand
Creates a score command instance
10 11 12 13 14 |
# File 'lib/stamina/command/redblue_command.rb', line 10 def initialize super("redblue", "[options] sample.adl", "Executes RedBlue (Regular Positive and Negative Inference) on a ADL sample and\n"\ "flushes the induced DFA on the standard output in ADL format as well") end |
Instance Method Details
#main(argv) ⇒ Object
Executes the command
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/stamina/command/redblue_command.rb', line 40 def main(argv) parse(argv, :sample_file) t1 = Time.now dfa = Stamina::Induction::RedBlue.execute(@sample, {:verbose => @verbose}) t2 = Time.now if @output_file File.open(@output_file, 'w') do |file| Stamina::ADL.print_automaton(dfa, file) end else Stamina::ADL.print_automaton(dfa, STDOUT) end puts "Executed in #{t2-t1} sec" if @verbose end |
#options ⇒ Object
Installs additional options
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stamina/command/redblue_command.rb', line 17 def super do |opt| opt.on("-v", "--verbose", "Verbose mode") do @verbose = true end opt.on("-o", "--output=OUTPUT", "Flush induced DFA in output file") do |value| assert_writable_file(value) @output_file = value end end end |
#sample_file=(file) ⇒ Object
Sets the sample file
31 32 33 34 35 36 37 |
# File 'lib/stamina/command/redblue_command.rb', line 31 def sample_file=(file) assert_readable_file(file) puts "Parsing sample and building PTA" if @verbose @sample = Stamina::ADL.parse_sample_file(file) rescue Stamina::ADL::ParseError raise ArgumentError, "#{file} is not a valid ADL sample file" end |