Class: Cucumber::Messages::Timestamp

Inherits:
Message
  • Object
show all
Defined in:
lib/cucumber/messages/timestamp.rb

Overview

Represents the Timestamp message in Cucumber’s message protocol.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

camelize, from_json, #to_h, #to_json

Constructor Details

#initialize(seconds: 0, nanos: 0) ⇒ Timestamp

Returns a new instance of Timestamp.



26
27
28
29
30
31
32
33
# File 'lib/cucumber/messages/timestamp.rb', line 26

def initialize(
  seconds: 0,
  nanos: 0
)
  @seconds = seconds
  @nanos = nanos
  super()
end

Instance Attribute Details

#nanosObject (readonly)

Non-negative fractions of a second at nanosecond resolution. Negative

second values with fractions must still have non-negative nanos values
that count forward in time. Must be from 0 to 999,999,999
inclusive.


24
25
26
# File 'lib/cucumber/messages/timestamp.rb', line 24

def nanos
  @nanos
end

#secondsObject (readonly)

Represents seconds of UTC time since Unix epoch

1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
9999-12-31T23:59:59Z inclusive.


16
17
18
# File 'lib/cucumber/messages/timestamp.rb', line 16

def seconds
  @seconds
end

Class Method Details

.from_h(hash) ⇒ Object

Returns a new Timestamp from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.

Cucumber::Messages::Timestamp.from_h(some_hash) # => #<Cucumber::Messages::Timestamp:0x... ...>


42
43
44
45
46
47
48
49
# File 'lib/cucumber/messages/timestamp.rb', line 42

def self.from_h(hash)
  return nil if hash.nil?

  new(
    seconds: hash[:seconds],
    nanos: hash[:nanos]
  )
end