Class: Prigner::CLI::Status
- Inherits:
-
Object
- Object
- Prigner::CLI::Status
- Defined in:
- lib/prigner/cli.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
- #format(key, format) ⇒ Object
- #increment! ⇒ Object
-
#initialize ⇒ Status
constructor
A new instance of Status.
- #setup(&block) ⇒ Object
- #start(title, &block) ⇒ Object
- #state(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Status
Returns a new instance of Status.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/prigner/cli.rb', line 56 def initialize @states = { :success => :done, :failure => :fail, :error => :err } @formats = { :title => "\n* %-74s\n", :info => " %-70s [%4s]\n" } @count = {} @states.keys.each{|k| @count[k] = 0 } end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
50 51 52 |
# File 'lib/prigner/cli.rb', line 50 def count @count end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
54 55 56 |
# File 'lib/prigner/cli.rb', line 54 def current @current end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
48 49 50 |
# File 'lib/prigner/cli.rb', line 48 def formats @formats end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
52 53 54 |
# File 'lib/prigner/cli.rb', line 52 def states @states end |
Instance Method Details
#format(key, format) ⇒ Object
80 81 82 |
# File 'lib/prigner/cli.rb', line 80 def format(key, format) @formats[key] = "#{format}\n" if @formats.has_key?key end |
#increment! ⇒ Object
84 85 86 |
# File 'lib/prigner/cli.rb', line 84 def increment! @count[@current] += 1 end |
#setup(&block) ⇒ Object
70 71 72 |
# File 'lib/prigner/cli.rb', line 70 def setup(&block) instance_eval(&block) end |
#start(title, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/prigner/cli.rb', line 88 def start(title, &block) printf @formats[:title], title hash = yield block hash.each do |, status| @current = status ? :success : :failure printf @formats[:info], , @states[@current] increment! end end |
#state(key, value) ⇒ Object
74 75 76 77 78 |
# File 'lib/prigner/cli.rb', line 74 def state(key, value) return unless @states.has_key?key @states[key] = value @count[key] = 0 end |