Class: Como::RuleDisplay
- Inherits:
-
ComoCommon
- Object
- ComoCommon
- Como::RuleDisplay
- Defined in:
- lib/como.rb
Overview
Display utility for RuleCheck. Usage model.
RuleDisplay.new.evalAndDisplay( &rule )
Example expansion of options:
|--# One of:
| |--# Adding in order:
| | |--<gcov>
| | |--<exclude>
| | |--<refreshed>
| |--<manifest>
| |--<pairs>
| |--<files>
Class Method Summary collapse
-
.print(prefixStr = " ", &rule) ⇒ Object
Eval rules to get an nested array and then display it.
Instance Method Summary collapse
-
#addPrefix(str) ⇒ Object
Increase prefix string.
-
#all(*args) ⇒ Object
All are given.
-
#any(*args) ⇒ Object
At least one is given.
-
#evalAndDisplay(&rule) ⇒ Object
Display method.
-
#follow(*args) ⇒ Object
Incremental options in order i.e.
-
#incr(*args) ⇒ Object
Incremental options in order i.e.
-
#initialize(prefixStr) ⇒ RuleDisplay
constructor
Create rule displayer.
-
#inv(*args) ⇒ Object
Logical inversion.
-
#meh(*args) ⇒ Object
Dont care.
-
#none ⇒ Object
Special condition where no arguments are given.
-
#one(*args) ⇒ Object
One of list given.
-
#p(str) ⇒ Object
Print prefix + str.
-
#printRule(arr) ⇒ Object
Recursively go through the nested array of rule items and print out rules.
-
#rmPrefix(item) ⇒ Object
Remove from prefix (either str or length ).
Methods inherited from ComoCommon
getIo, runHook, setHook, setIo
Constructor Details
#initialize(prefixStr) ⇒ RuleDisplay
Create rule displayer.
2368 2369 2370 2371 |
# File 'lib/como.rb', line 2368 def initialize( prefixStr ) # Prefix string for lines. Rules add/rm from it. @prefixStr = prefixStr end |
Class Method Details
.print(prefixStr = " ", &rule) ⇒ Object
Eval rules to get an nested array and then display it.
2362 2363 2364 2365 |
# File 'lib/como.rb', line 2362 def RuleDisplay.print( prefixStr = " ", &rule ) rd = RuleDisplay.new( prefixStr ) rd.evalAndDisplay( &rule ) end |
Instance Method Details
#addPrefix(str) ⇒ Object
Increase prefix string.
2379 2380 2381 |
# File 'lib/como.rb', line 2379 def addPrefix( str ) @prefixStr += str end |
#all(*args) ⇒ Object
All are given.
2443 2444 2445 |
# File 'lib/como.rb', line 2443 def all( *args ) [ "All of", *args ] end |
#any(*args) ⇒ Object
At least one is given.
2438 2439 2440 |
# File 'lib/como.rb', line 2438 def any( *args ) [ "One or more of", *args ] end |
#evalAndDisplay(&rule) ⇒ Object
Display method.
2374 2375 2376 |
# File 'lib/como.rb', line 2374 def evalAndDisplay( &rule ) printRule( instance_eval( &rule ) ) end |
#follow(*args) ⇒ Object
Incremental options in order i.e. have to have all later if had first.
2428 2429 2430 |
# File 'lib/como.rb', line 2428 def follow( *args ) [ "If first then rest", *args ] end |
#incr(*args) ⇒ Object
Incremental options in order i.e. have to have previous to have later.
2422 2423 2424 |
# File 'lib/como.rb', line 2422 def incr( *args ) [ "Adding in order", *args ] end |
#inv(*args) ⇒ Object
Logical inversion.
2448 2449 2450 |
# File 'lib/como.rb', line 2448 def inv( *args ) [ "Not", *args ] end |
#meh(*args) ⇒ Object
Dont care.
2453 2454 2455 |
# File 'lib/como.rb', line 2453 def meh( *args ) [ "Ignoring", *args ] end |
#none ⇒ Object
Special condition where no arguments are given.
2416 2417 2418 |
# File 'lib/como.rb', line 2416 def none [ "NONE" ] end |
#one(*args) ⇒ Object
One of list given.
2433 2434 2435 |
# File 'lib/como.rb', line 2433 def one( *args ) [ "One of", *args ] end |
#p(str) ⇒ Object
Print prefix + str.
2394 2395 2396 |
# File 'lib/como.rb', line 2394 def p( str ) @@io.puts( @prefixStr + str ) end |
#printRule(arr) ⇒ Object
Recursively go through the nested array of rule items and print out rules.
2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 |
# File 'lib/como.rb', line 2400 def printRule( arr ) p( "|--# #{arr[0]}:" ) item = "| " addPrefix( item ) arr[1..-1].each do |i| if i.class == Array printRule( i ) else p( "|--<#{i}>" ) end end rmPrefix( item ) end |
#rmPrefix(item) ⇒ Object
Remove from prefix (either str or length ).
2384 2385 2386 2387 2388 2389 2390 2391 |
# File 'lib/como.rb', line 2384 def rmPrefix( item ) if item.class == String cnt = item.length else cnt = item end @prefixStr = @prefixStr[0..-(cnt+1)] end |