Class: Lemans::Result::Phase

Inherits:
Object
  • Object
show all
Defined in:
lib/lemans/result.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, started_at: nil, finished_at: nil) ⇒ Phase

Returns a new instance of Phase.



88
89
90
91
92
# File 'lib/lemans/result.rb', line 88

def initialize(name, started_at: nil, finished_at: nil)
  @name = name.to_sym
  @started_at = started_at || Time.now.utc
  @finished_at = finished_at
end

Instance Attribute Details

#finished_atObject (readonly) Also known as: finished?

Returns the value of attribute finished_at.



84
85
86
# File 'lib/lemans/result.rb', line 84

def finished_at
  @finished_at
end

#nameObject (readonly)

Returns the value of attribute name.



84
85
86
# File 'lib/lemans/result.rb', line 84

def name
  @name
end

#started_atObject (readonly)

Returns the value of attribute started_at.



84
85
86
# File 'lib/lemans/result.rb', line 84

def started_at
  @started_at
end

Class Method Details

.from_json(data) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/lemans/result.rb', line 106

def self.from_json(data)
  name, started_at_str, finished_at_str = data.values_at(:name, :started_at, :finished_at)

  started_at = Time.parse(started_at_str) if started_at_str
  finished_at = Time.parse(finished_at_str) if finished_at_str

  new(name, started_at:, finished_at:)
end

Instance Method Details

#as_jsonObject



98
99
100
101
102
103
104
# File 'lib/lemans/result.rb', line 98

def as_json(**)
  {
    name:,
    started_at: started_at.iso8601(6),
    finished_at: finished_at&.iso8601(6)
  }
end

#finish!(time = nil) ⇒ Object



94
95
96
# File 'lib/lemans/result.rb', line 94

def finish!(time = nil)
  @finished_at = time || Time.now.utc
end