Class: Como::RuleDisplay
- Inherits:
-
ComoCommon
- Object
- ComoCommon
- Como::RuleDisplay
- 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
-
.print(prefixStr = " ", &rule) ⇒ Object
Eval rules to get an nested array and then display it.
Instance Method Summary collapse
-
#addPrefix(str) ⇒ Object
Increase prefix string.
-
#all(*args) ⇒ Object
All are given.
-
#any(*args) ⇒ Object
At least one is given.
- #evalAndDisplay(&rule) ⇒ Object
-
#follow(*args) ⇒ Object
Incremental options in order i.e.
-
#incr(*args) ⇒ Object
Incremental options in order i.e.
-
#initialize(prefixStr) ⇒ RuleDisplay
constructor
A new instance of RuleDisplay.
-
#inv(*args) ⇒ Object
Logical inversion.
-
#meh(*args) ⇒ Object
Dont care.
-
#none ⇒ Object
Special condition where no arguments are given.
-
#one(*args) ⇒ Object
One of list given.
-
#p(str) ⇒ Object
Print prefix + str.
-
#printRule(arr) ⇒ Object
Recursively go through the nested array of rule items and print out rules.
-
#rmPrefix(item) ⇒ Object
Remove from prefix (either str or length ).
Methods inherited from ComoCommon
Constructor Details
#initialize(prefixStr) ⇒ RuleDisplay
Returns a new instance of RuleDisplay.
2014 2015 2016 2017 |
# File 'lib/como.rb', line 2014 def initialize( prefixStr ) # Prefix string for lines. Rules add/rm from it. @prefixStr = prefixStr end |
Class Method Details
.print(prefixStr = " ", &rule) ⇒ Object
Eval rules to get an nested array and then display it.
2009 2010 2011 2012 |
# File 'lib/como.rb', line 2009 def RuleDisplay.print( prefixStr = " ", &rule ) rd = RuleDisplay.new( prefixStr ) rd.evalAndDisplay( &rule ) end |
Instance Method Details
#addPrefix(str) ⇒ Object
Increase prefix string.
2024 2025 2026 |
# File 'lib/como.rb', line 2024 def addPrefix( str ) @prefixStr += str end |
#all(*args) ⇒ Object
All are given.
2088 2089 2090 |
# File 'lib/como.rb', line 2088 def all( *args ) [ "All of", *args ] end |
#any(*args) ⇒ Object
At least one is given.
2083 2084 2085 |
# File 'lib/como.rb', line 2083 def any( *args ) [ "One or more of", *args ] end |
#evalAndDisplay(&rule) ⇒ Object
2019 2020 2021 |
# File 'lib/como.rb', line 2019 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.
2073 2074 2075 |
# File 'lib/como.rb', line 2073 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.
2067 2068 2069 |
# File 'lib/como.rb', line 2067 def incr( *args ) [ "Adding in order", *args ] end |
#inv(*args) ⇒ Object
Logical inversion.
2093 2094 2095 |
# File 'lib/como.rb', line 2093 def inv( *args ) [ "Not", *args ] end |
#meh(*args) ⇒ Object
Dont care.
2098 2099 2100 |
# File 'lib/como.rb', line 2098 def meh( *args ) [ "Ignoring", *args ] end |
#none ⇒ Object
Special condition where no arguments are given.
2061 2062 2063 |
# File 'lib/como.rb', line 2061 def none [ "NONE" ] end |
#one(*args) ⇒ Object
One of list given.
2078 2079 2080 |
# File 'lib/como.rb', line 2078 def one( *args ) [ "One of", *args ] end |
#p(str) ⇒ Object
Print prefix + str.
2039 2040 2041 |
# File 'lib/como.rb', line 2039 def p( str ) @@io.puts( @prefixStr + str ) end |
#printRule(arr) ⇒ Object
Recursively go through the nested array of rule items and print out rules.
2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 |
# File 'lib/como.rb', line 2045 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 ).
2029 2030 2031 2032 2033 2034 2035 2036 |
# File 'lib/como.rb', line 2029 def rmPrefix( item ) if item.class == String cnt = item.length else cnt = item end @prefixStr = @prefixStr[0..-(cnt+1)] end |