Class: Bitbar::Concourse::BuildPresenter
- Inherits:
-
Object
- Object
- Bitbar::Concourse::BuildPresenter
- Extended by:
- Forwardable
- Defined in:
- lib/bitbar/concourse/build_presenter.rb
Instance Method Summary collapse
- #elapsed_time ⇒ Object
-
#initialize(build) ⇒ BuildPresenter
constructor
A new instance of BuildPresenter.
- #relative_end_time ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(build) ⇒ BuildPresenter
Returns a new instance of BuildPresenter.
13 14 15 16 |
# File 'lib/bitbar/concourse/build_presenter.rb', line 13 def initialize(build) raise 'Build must not be nil' if build.nil? @build = build end |
Instance Method Details
#elapsed_time ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bitbar/concourse/build_presenter.rb', line 34 def elapsed_time case difference = @build.end_time.to_i - @build.start_time.to_i when 0..59 "#{difference} seconds" when 60..80 'one minute' when 81..(60 * 25) "#{difference / 60} minutes" when (60 * 26)..(60 * 35) 'about half an hour' else "#{difference}s" end end |
#relative_end_time ⇒ Object
49 50 51 |
# File 'lib/bitbar/concourse/build_presenter.rb', line 49 def relative_end_time @build.end_time&.extend(RelativeTime)&.to_relative end |
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bitbar/concourse/build_presenter.rb', line 18 def to_s icon = @build.success? ? '✅' : '❌' lines = [ "#{icon} #{@build.job_name} - build ##{@build.name} | href=#{@build.url}", "finished #{relative_end_time}; took #{elapsed_time}" ] if next_build = @build.next started_at = next_build.start_time.extend(RelativeTime).to_relative lines << "next build (##{next_build.name}) started #{started_at} | href=#{next_build.url}" end lines.join("\n") end |