Class: Saruman::ObserverMenuBuilder
- Inherits:
-
Object
- Object
- Saruman::ObserverMenuBuilder
- Includes:
- Virtus
- Defined in:
- lib/saruman.rb
Constant Summary collapse
- BASE_DIR =
File.dirname(__FILE__)
- OBSERVER_EVENTS_FILE_PATH =
BASE_DIR+"/saruman/generators/observer/observer_events.csv"
Instance Method Summary collapse
- #display_choices(menu) ⇒ Object
-
#initialize(menu) ⇒ ObserverMenuBuilder
constructor
A new instance of ObserverMenuBuilder.
-
#pad_command_line(string, offset, index) ⇒ Object
make the choices pretty, longest string length minus offset, and take into account number of base digits of the choice.
Constructor Details
#initialize(menu) ⇒ ObserverMenuBuilder
Returns a new instance of ObserverMenuBuilder.
265 266 267 268 269 270 271 272 273 274 |
# File 'lib/saruman.rb', line 265 def initialize() @events_file = File.open(OBSERVER_EVENTS_FILE_PATH, 'r') @observer_events = [] @events_file.readlines.each do |row| cells = row.strip().split(",") @observer_events.push({:event_name => cells[2], :file => cells[0], :line => cells[1]}) end @events_file.close display_choices() end |
Instance Method Details
#display_choices(menu) ⇒ Object
286 287 288 289 290 291 |
# File 'lib/saruman.rb', line 286 def display_choices() observer_events.each_with_index do |event,index| .choice("#{event[:event_name]} #{pad_command_line(event[:event_name],67,index+1)} File: #{event[:file]} #{pad_command_line(event[:file],96,index+1)} Line: #{event[:line]}") { decisions.push(event[:event_name])} end end |
#pad_command_line(string, offset, index) ⇒ Object
make the choices pretty, longest string length minus offset, and take into account number of base digits of the choice
277 278 279 280 281 282 283 284 |
# File 'lib/saruman.rb', line 277 def pad_command_line(string, offset, index) padding = "" l = ((offset - string.length) - index.to_s.length) l.times do padding << " " end padding end |