Class: Cutter::Stamper

Inherits:
Object show all
Extended by:
ClassMethods
Includes:
ColoredOutputs
Defined in:
lib/cutter/stamper.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

last, pop, push, scope

Methods included from ColoredOutputs

included

Methods included from ColoredOutputs::ClassMethods

#colors, #colors?, #colors_config, #turn_colors

Constructor Details

#initialize(label) ⇒ Stamper

Returns a new instance of Stamper.



83
84
85
86
# File 'lib/cutter/stamper.rb', line 83

def initialize label
  @label = label
  @indent = 0
end

Instance Attribute Details

#indentObject



109
110
111
# File 'lib/cutter/stamper.rb', line 109

def indent
  @indent ||= 0
end

#labelObject (readonly)

Returns the value of attribute label.



77
78
79
# File 'lib/cutter/stamper.rb', line 77

def label
  @label
end

#time_initialObject

Returns the value of attribute time_initial.



78
79
80
# File 'lib/cutter/stamper.rb', line 78

def time_initial
  @time_initial
end

Class Method Details

.loud!Object



96
97
98
# File 'lib/cutter/stamper.rb', line 96

def self.loud!
  self.turn :on
end

.off?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/cutter/stamper.rb', line 105

def self.off?
  !on?
end

.on?Boolean

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/cutter/stamper.rb', line 100

def self.on?
  @@state ||= :on
  @@state == :on
end

.quiet!Object



92
93
94
# File 'lib/cutter/stamper.rb', line 92

def self.quiet!
  self.turn :off
end

.turn(state = :on) ⇒ Object



88
89
90
# File 'lib/cutter/stamper.rb', line 88

def self.turn state = :on
  @@state = state
end

Instance Method Details

#[](key) ⇒ Object



127
128
129
# File 'lib/cutter/stamper.rb', line 127

def [] key
  messages[key]
end

#messagesObject



123
124
125
# File 'lib/cutter/stamper.rb', line 123

def messages
  @messages ||= {}
end

#msg(label) ⇒ Object Also known as: <<



117
118
119
# File 'lib/cutter/stamper.rb', line 117

def msg label
  messages[label.keys.first] = label.values.first
end

#nindentObject



113
114
115
# File 'lib/cutter/stamper.rb', line 113

def nindent
  @indent +1
end

#stamp(lbl = nil) ⇒ Object Also known as: stamp!



131
132
133
134
135
136
137
# File 'lib/cutter/stamper.rb', line 131

def stamp lbl = nil
  return if Stamper.off?
  message = messages[lbl] || lbl.to_s
  time_passed = Time.now.ms_since time_initial
  print "  " * nindent
  printf("stamp: %7dms   #{message}\n", time_passed)
end