Class: RSpec::By::Formatter::Bullet

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/by/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', nested = false) ⇒ Bullet

Returns a new instance of Bullet.



93
94
95
96
97
# File 'lib/rspec/by/formatter.rb', line 93

def initialize(message = '', nested = false)
  @t0 = RSpec::Core::Time.now
  @nested = nested
  @message = message
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



92
93
94
# File 'lib/rspec/by/formatter.rb', line 92

def message
  @message
end

Instance Method Details

#delta_tObject



99
100
101
102
# File 'lib/rspec/by/formatter.rb', line 99

def delta_t
  delta_t = RSpec::Core::Time.now - @t0
  format_time(delta_t)
end

#format_seconds(float, precision = 2) ⇒ Object



126
127
128
129
# File 'lib/rspec/by/formatter.rb', line 126

def format_seconds(float, precision = 2)
  #precision ||= (float < 1) ? 5 : 2
  sprintf("%.#{precision}f", float)
end

#format_time(duration) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/rspec/by/formatter.rb', line 116

def format_time(duration)
  if duration > 60
    minutes = duration.to_i / 60
    seconds = duration - minutes * 60
    "#{minutes}m #{format_seconds(seconds)}s"
  else
    "#{format_seconds(duration)}s"
  end
end

#nestObject



108
109
110
# File 'lib/rspec/by/formatter.rb', line 108

def nest
  @nested = true
end

#nested?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/rspec/by/formatter.rb', line 112

def nested?
  @nested
end

#offsetObject



104
105
106
# File 'lib/rspec/by/formatter.rb', line 104

def offset
  @message.size
end