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, setIo

Constructor Details

- (RuleDisplay) initialize(prefixStr)

A new instance of RuleDisplay



1981
1982
1983
1984
# File 'lib/como.rb', line 1981

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.



1976
1977
1978
1979
# File 'lib/como.rb', line 1976

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

Instance Method Details

- (Object) addPrefix(str)

Increase prefix string.



1991
1992
1993
# File 'lib/como.rb', line 1991

def addPrefix( str )
    @prefixStr += str
end

- (Object) all(*args)

All are given.



2055
2056
2057
# File 'lib/como.rb', line 2055

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

- (Object) any(*args)

At least one is given.



2050
2051
2052
# File 'lib/como.rb', line 2050

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

- (Object) evalAndDisplay(&rule)



1986
1987
1988
# File 'lib/como.rb', line 1986

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.



2040
2041
2042
# File 'lib/como.rb', line 2040

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.



2034
2035
2036
# File 'lib/como.rb', line 2034

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

- (Object) inv(*args)

Logical inversion.



2060
2061
2062
# File 'lib/como.rb', line 2060

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

- (Object) meh(*args)

Dont care.



2065
2066
2067
# File 'lib/como.rb', line 2065

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

- (Object) none

Special condition where no arguments are given.



2028
2029
2030
# File 'lib/como.rb', line 2028

def none
    [ "NONE" ]
end

- (Object) one(*args)

One of list given.



2045
2046
2047
# File 'lib/como.rb', line 2045

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

- (Object) p(str)

Print prefix + str.



2006
2007
2008
# File 'lib/como.rb', line 2006

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

- (Object) printRule(arr)

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



2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
# File 'lib/como.rb', line 2012

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



1996
1997
1998
1999
2000
2001
2002
2003
# File 'lib/como.rb', line 1996

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