Class: Como::RuleDisplay

Inherits:
ComoCommon show all
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)

Instance Method Summary (collapse)

Methods inherited from ComoCommon

getIo, runHook, setHook, setIo

Constructor Details

- (RuleDisplay) initialize(prefixStr)

Create rule displayer.



2336
2337
2338
2339
# File 'lib/como.rb', line 2336

def initialize( prefixStr )
    # Prefix string for lines. Rules add/rm from it.
    @prefixStr = prefixStr
end

Class Method Details

Eval rules to get an nested array and then display it.



2330
2331
2332
2333
# File 'lib/como.rb', line 2330

def RuleDisplay.print( prefixStr = "    ", &rule )
    rd = RuleDisplay.new( prefixStr )
    rd.evalAndDisplay( &rule )
end

Instance Method Details

- (Object) addPrefix(str)

Increase prefix string.



2347
2348
2349
# File 'lib/como.rb', line 2347

def addPrefix( str )
    @prefixStr += str
end

- (Object) all(*args)

All are given.



2411
2412
2413
# File 'lib/como.rb', line 2411

def all( *args )
    [ "All of", *args ]
end

- (Object) any(*args)

At least one is given.



2406
2407
2408
# File 'lib/como.rb', line 2406

def any( *args )
    [ "One or more of", *args ]
end

- (Object) evalAndDisplay(&rule)

Display method.



2342
2343
2344
# File 'lib/como.rb', line 2342

def evalAndDisplay( &rule )
    printRule( instance_eval( &rule ) )
end

- (Object) follow(*args)

Incremental options in order i.e. have to have all later if had first.



2396
2397
2398
# File 'lib/como.rb', line 2396

def follow( *args )
    [ "If first then rest", *args ]
end

- (Object) incr(*args)

Incremental options in order i.e. have to have previous to have later.



2390
2391
2392
# File 'lib/como.rb', line 2390

def incr( *args )
    [ "Adding in order", *args ]
end

- (Object) inv(*args)

Logical inversion.



2416
2417
2418
# File 'lib/como.rb', line 2416

def inv( *args )
    [ "Not", *args ]
end

- (Object) meh(*args)

Dont care.



2421
2422
2423
# File 'lib/como.rb', line 2421

def meh( *args )
    [ "Ignoring", *args ]
end

- (Object) none

Special condition where no arguments are given.



2384
2385
2386
# File 'lib/como.rb', line 2384

def none
    [ "NONE" ]
end

- (Object) one(*args)

One of list given.



2401
2402
2403
# File 'lib/como.rb', line 2401

def one( *args )
    [ "One of", *args ]
end

- (Object) p(str)

Print prefix + str.



2362
2363
2364
# File 'lib/como.rb', line 2362

def p( str )
    @@io.puts( @prefixStr + str )
end

- (Object) printRule(arr)

Recursively go through the nested array of rule items and print out rules.



2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
# File 'lib/como.rb', line 2368

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

- (Object) rmPrefix(item)

Remove from prefix (either str or length ).



2352
2353
2354
2355
2356
2357
2358
2359
# File 'lib/como.rb', line 2352

def rmPrefix( item )
    if item.class == String
        cnt = item.length
    else
        cnt = item
    end
    @prefixStr = @prefixStr[0..-(cnt+1)]
end