Class: SFML::Time
- Inherits:
-
Object
- Object
- SFML::Time
- Includes:
- Comparable
- Defined in:
- lib/sfml/system/time.rb
Overview
Represents a time value. Stored internally as microseconds (int64), same as sfTime in CSFML. Immutable and comparable.
SFML::Time.seconds(1.5) #=> 1_500_000 µs
SFML::Time.milliseconds(500)
SFML::Time.microseconds(42)
SFML::Time.zero
Instance Attribute Summary collapse
-
#microseconds ⇒ Object
readonly
Returns the value of attribute microseconds.
Class Method Summary collapse
-
.from_native(struct) ⇒ Object
:nodoc:.
- .microseconds(value) ⇒ Object
- .milliseconds(value) ⇒ Object
- .seconds(value) ⇒ Object
- .zero ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #<=>(other) ⇒ Object
- #as_microseconds ⇒ Object
- #as_milliseconds ⇒ Object
- #as_seconds ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(microseconds) ⇒ Time
constructor
A new instance of Time.
-
#to_native ⇒ Object
:nodoc:.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(microseconds) ⇒ Time
Returns a new instance of Time.
19 20 21 22 |
# File 'lib/sfml/system/time.rb', line 19 def initialize(microseconds) @microseconds = Integer(microseconds) freeze end |
Instance Attribute Details
#microseconds ⇒ Object (readonly)
Returns the value of attribute microseconds.
12 13 14 |
# File 'lib/sfml/system/time.rb', line 12 def microseconds @microseconds end |
Class Method Details
.from_native(struct) ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/sfml/system/time.rb', line 40 def self.from_native(struct) # :nodoc: new(struct[:microseconds]) end |
.microseconds(value) ⇒ Object
16 |
# File 'lib/sfml/system/time.rb', line 16 def self.microseconds(value) = new(Integer(value)) |
.milliseconds(value) ⇒ Object
15 |
# File 'lib/sfml/system/time.rb', line 15 def self.milliseconds(value) = new(Integer(value) * 1_000) |
.seconds(value) ⇒ Object
14 |
# File 'lib/sfml/system/time.rb', line 14 def self.seconds(value) = new((value * 1_000_000).to_i) |
.zero ⇒ Object
17 |
# File 'lib/sfml/system/time.rb', line 17 def self.zero = new(0) |
Instance Method Details
#+(other) ⇒ Object
28 |
# File 'lib/sfml/system/time.rb', line 28 def +(other) = Time.new(@microseconds + other.microseconds) |
#-(other) ⇒ Object
29 |
# File 'lib/sfml/system/time.rb', line 29 def -(other) = Time.new(@microseconds - other.microseconds) |
#<=>(other) ⇒ Object
31 |
# File 'lib/sfml/system/time.rb', line 31 def <=>(other) = @microseconds <=> other.microseconds |
#as_microseconds ⇒ Object
26 |
# File 'lib/sfml/system/time.rb', line 26 def as_microseconds = @microseconds |
#as_milliseconds ⇒ Object
25 |
# File 'lib/sfml/system/time.rb', line 25 def as_milliseconds = @microseconds / 1_000 |
#as_seconds ⇒ Object
24 |
# File 'lib/sfml/system/time.rb', line 24 def as_seconds = @microseconds / 1_000_000.0 |
#eql?(other) ⇒ Boolean Also known as: ==
34 |
# File 'lib/sfml/system/time.rb', line 34 def eql?(other) = other.is_a?(Time) && @microseconds == other.microseconds |
#hash ⇒ Object
33 |
# File 'lib/sfml/system/time.rb', line 33 def hash = @microseconds.hash |
#to_native ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/sfml/system/time.rb', line 44 def to_native # :nodoc: C::System::Time.new.tap { |t| t[:microseconds] = @microseconds } end |
#to_s ⇒ Object Also known as: inspect
37 |
# File 'lib/sfml/system/time.rb', line 37 def to_s = "#<SFML::Time #{as_seconds}s>" |