Class: Prigner::CLI::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/prigner/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatus

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

#countObject (readonly)

Returns the value of attribute count.



50
51
52
# File 'lib/prigner/cli.rb', line 50

def count
  @count
end

#currentObject (readonly)

Returns the value of attribute current.



54
55
56
# File 'lib/prigner/cli.rb', line 54

def current
  @current
end

#formatsObject (readonly)

Returns the value of attribute formats.



48
49
50
# File 'lib/prigner/cli.rb', line 48

def formats
  @formats
end

#statesObject (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 |message, status|
    @current = status ? :success : :failure
    printf @formats[:info], message, @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