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.



2213
2214
2215
2216
# File 'lib/como.rb', line 2213

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.



2207
2208
2209
2210
# File 'lib/como.rb', line 2207

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

Instance Method Details

#addPrefix(str) ⇒ Object

Increase prefix string.



2224
2225
2226
# File 'lib/como.rb', line 2224

def addPrefix( str )
    @prefixStr += str
end

#all(*args) ⇒ Object

All are given.



2288
2289
2290
# File 'lib/como.rb', line 2288

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

#any(*args) ⇒ Object

At least one is given.



2283
2284
2285
# File 'lib/como.rb', line 2283

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

#evalAndDisplay(&rule) ⇒ Object

Display method.



2219
2220
2221
# File 'lib/como.rb', line 2219

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.



2273
2274
2275
# File 'lib/como.rb', line 2273

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.



2267
2268
2269
# File 'lib/como.rb', line 2267

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

#inv(*args) ⇒ Object

Logical inversion.



2293
2294
2295
# File 'lib/como.rb', line 2293

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

#meh(*args) ⇒ Object

Dont care.



2298
2299
2300
# File 'lib/como.rb', line 2298

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

#noneObject

Special condition where no arguments are given.



2261
2262
2263
# File 'lib/como.rb', line 2261

def none
    [ "NONE" ]
end

#one(*args) ⇒ Object

One of list given.



2278
2279
2280
# File 'lib/como.rb', line 2278

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

#p(str) ⇒ Object

Print prefix + str.



2239
2240
2241
# File 'lib/como.rb', line 2239

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

#printRule(arr) ⇒ Object

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



2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
# File 'lib/como.rb', line 2245

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



2229
2230
2231
2232
2233
2234
2235
2236
# File 'lib/como.rb', line 2229

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