Module: Bali::Printer
- Defined in:
- lib/bali/printer.rb
Overview
module that would allow all defined rules to be printed for check
Constant Summary collapse
- SEPARATOR =
" " * 6
- SUBTARGET_TITLE_SEPARATOR =
SEPARATOR + ("-" * 80) + "\n"
Class Method Summary collapse
Class Method Details
.pretty_print ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bali/printer.rb', line 11 def pretty_print output = StringIO.new # build up the string for pretty printing rules Bali::RULE_CLASS_MAP.each do |klass, rule_class| output << "===== #{klass.to_s} =====\n\n" rule_class.rule_groups.each do |subtarget, rule_group| print_rule_group(rule_group, output) end if rule_class.others_rule_group.rules.any? print_rule_group(rule_class.others_rule_group, output) end output << "\n\n" end output << "\n\n" output << DateTime.now.strftime("Printed at %d-%m-%Y %I:%M%p %Z") output.string end |
.print_rule_group(rule_group, target_io) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bali/printer.rb', line 34 def print_rule_group(rule_group, target_io) target = rule_group.target.to_s subtarget = rule_group.subtarget.to_s.capitalize subtarget = "Others" if subtarget == "__*__" is_zeus = rule_group.zeus? is_plant = rule_group.plant? counter = 0 target_io << "#{SEPARATOR}#{subtarget}, can all: #{is_zeus}, cannot all: #{is_plant}\n" target_io << SUBTARGET_TITLE_SEPARATOR if is_zeus target_io << "#{SEPARATOR} #{counter+=1}. #{subtarget} can do anything except if explicitly stated otherwise\n" elsif is_plant target_io << "#{SEPARATOR} #{counter+=1}. #{subtarget} cannot do anything except if explicitly stated otherwise\n" end rule_group.rules.each do |rule| written_rule = StringIO.new written_rule << "#{SEPARATOR} #{counter+=1}. #{subtarget} #{rule.auth_val} #{rule.operation} #{target}" if rule.has_decider? written_rule << ", with condition" end written_rule << "\n" target_io << written_rule.string end target_io << "\n" end |