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

#initialize(prefixStr) ⇒ RuleDisplay

Create rule displayer.



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

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.



2324
2325
2326
2327
# File 'lib/como.rb', line 2324

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

Instance Method Details

#addPrefix(str) ⇒ Object

Increase prefix string.



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

def addPrefix( str )
    @prefixStr += str
end

#all(*args) ⇒ Object

All are given.



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

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

#any(*args) ⇒ Object

At least one is given.



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

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

#evalAndDisplay(&rule) ⇒ Object

Display method.



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

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.



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

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.



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

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

#inv(*args) ⇒ Object

Logical inversion.



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

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

#meh(*args) ⇒ Object

Dont care.



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

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

#noneObject

Special condition where no arguments are given.



2378
2379
2380
# File 'lib/como.rb', line 2378

def none
    [ "NONE" ]
end

#one(*args) ⇒ Object

One of list given.



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

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

#p(str) ⇒ Object

Print prefix + str.



2356
2357
2358
# File 'lib/como.rb', line 2356

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

#printRule(arr) ⇒ Object

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



2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
# File 'lib/como.rb', line 2362

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 ).



2346
2347
2348
2349
2350
2351
2352
2353
# File 'lib/como.rb', line 2346

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