Class: CTioga::CTable
- Inherits:
-
Object
- Object
- CTioga::CTable
- Defined in:
- lib/CTioga/ctable.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#block ⇒ Object
Returns the value of attribute block.
-
#parser ⇒ Object
This can be used by various scripts to add hooks on the parser.
-
#print_banner ⇒ Object
Returns the value of attribute print_banner.
Class Method Summary collapse
-
.run(args, &a) ⇒ Object
A simple convenience function.
Instance Method Summary collapse
-
#initialize ⇒ CTable
constructor
A new instance of CTable.
- #process_data_set(set) ⇒ Object
-
#run(cmd_line_args, *extra_args, &a) ⇒ Object
Runs the program with the given command-line arguments.
Methods included from Backends
#backend, #backends, #current_push_filter, #expand_spec, #init_backend_structure, #prepare_backend_options, #set_backend, #xy_data_set
Methods included from Log
#identify, #init_logger, #logger, #logger_options, #spawn
Constructor Details
#initialize ⇒ CTable
Returns a new instance of CTable.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/CTioga/ctable.rb', line 46 def initialize init_logger init_backend_structure @args = [] @block = proc { |set,data,*a| puts "# #{set}" data.each do |x,y| puts "#{x}\t#{y}" end } @print_banner = true @parser = OptionParser.new (@parser) @parser.separator "" @parser.separator "Code execution" @parser.on("-e", "--execute BLOCK", "Executes the given ruby code for each set, " , "yielding the set name and its data for each." , "Use 'set' to refer to the set's name, and 'data' " , "for it's data" ) do |code| self.block = eval "proc { |set,data,*args| #{code}}" end @parser.on("-f", "--file FILE", "Same as -e except it's specifying a file which is ", "read an executed with the same parameters as the BLOCK" ) do |file| self.block = eval "proc { |set,data,*args| #{IO.readlines(file).join}}" end @parser.on("-r", "--require FILE", "Ask ruby to require the file before data processing.", "You can use it to declare some external functions." ) do |file| require file end @parser.on("-a", "--arg a", "Provides additionnal arguments to your code") do |arg| @args << arg end end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
38 39 40 |
# File 'lib/CTioga/ctable.rb', line 38 def args @args end |
#block ⇒ Object
Returns the value of attribute block.
37 38 39 |
# File 'lib/CTioga/ctable.rb', line 37 def block @block end |
#parser ⇒ Object
This can be used by various scripts to add hooks on the parser. You can alternatively use your own parser beforehand, but you lose the benefits of the online help.
44 45 46 |
# File 'lib/CTioga/ctable.rb', line 44 def parser @parser end |
#print_banner ⇒ Object
Returns the value of attribute print_banner.
39 40 41 |
# File 'lib/CTioga/ctable.rb', line 39 def @print_banner end |
Class Method Details
.run(args, &a) ⇒ Object
A simple convenience function.
129 130 131 |
# File 'lib/CTioga/ctable.rb', line 129 def self.run(args, &a) self.new.run(args,&a) end |
Instance Method Details
#process_data_set(set) ⇒ Object
95 96 97 98 |
# File 'lib/CTioga/ctable.rb', line 95 def process_data_set(set) data = xy_data_set(set) @block.call(set,data,*@args) end |
#run(cmd_line_args, *extra_args, &a) ⇒ Object
Runs the program with the given command-line arguments. If a block is given, use this block rather than the default one. Be careful, though, as command-line arguments can still override this.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/CTioga/ctable.rb', line 103 def run(cmd_line_args,*extra_args, &a) $stderr.puts <<"EOBANNER" if @print_banner This is ctable version #{Version.version}, copyright (C) 2006-2007 Vincent Fourmond. ctable comes with absolutely NO WARRANTY. This is free software, you are welcome to redistribute it under certain conditions. See the COPYING file in the original tarball for details. You are also welcome to contribute if you like it, see in the manual page where to ask. EOBANNER # Use the user-given block if block_given? @block = a end @args = extra_args @parser.order(cmd_line_args) do |spec| # We use Backend#expand to leave room for the backend to # interpret the text as many different sets. (spec).each do |set| process_data_set(set) end end end |