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>

Constant Summary

Constants inherited from ComoCommon

ComoCommon::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComoCommon

getIo, runHook, setHook, setIo

Constructor Details

#initialize(prefixStr) ⇒ RuleDisplay



2099
2100
2101
2102
# File 'lib/como.rb', line 2099

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.



2094
2095
2096
2097
# File 'lib/como.rb', line 2094

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

Instance Method Details

#addPrefix(str) ⇒ Object

Increase prefix string.



2109
2110
2111
# File 'lib/como.rb', line 2109

def addPrefix( str )
    @prefixStr += str
end

#all(*args) ⇒ Object

All are given.



2173
2174
2175
# File 'lib/como.rb', line 2173

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

#any(*args) ⇒ Object

At least one is given.



2168
2169
2170
# File 'lib/como.rb', line 2168

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

#evalAndDisplay(&rule) ⇒ Object



2104
2105
2106
# File 'lib/como.rb', line 2104

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.



2158
2159
2160
# File 'lib/como.rb', line 2158

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.



2152
2153
2154
# File 'lib/como.rb', line 2152

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

#inv(*args) ⇒ Object

Logical inversion.



2178
2179
2180
# File 'lib/como.rb', line 2178

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

#meh(*args) ⇒ Object

Dont care.



2183
2184
2185
# File 'lib/como.rb', line 2183

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

#noneObject

Special condition where no arguments are given.



2146
2147
2148
# File 'lib/como.rb', line 2146

def none
    [ "NONE" ]
end

#one(*args) ⇒ Object

One of list given.



2163
2164
2165
# File 'lib/como.rb', line 2163

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

#p(str) ⇒ Object

Print prefix + str.



2124
2125
2126
# File 'lib/como.rb', line 2124

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

#printRule(arr) ⇒ Object

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



2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
# File 'lib/como.rb', line 2130

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



2114
2115
2116
2117
2118
2119
2120
2121
# File 'lib/como.rb', line 2114

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