Class: StardateInterval
- Inherits:
-
Object
- Object
- StardateInterval
- Defined in:
- lib/stardate_interval.rb
Instance Attribute Summary collapse
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
Instance Method Summary collapse
- #-@ ⇒ Object
- #days ⇒ Object
- #hours ⇒ Object
-
#initialize(start, stop) ⇒ StardateInterval
constructor
A new instance of StardateInterval.
- #inspect ⇒ Object
- #lifespans ⇒ Object
- #milliseconds ⇒ Object
- #minutes ⇒ Object
- #months ⇒ Object
- #seconds ⇒ Object
- #to_human(precision = 3) ⇒ Object
- #weeks ⇒ Object
- #years ⇒ Object
Constructor Details
#initialize(start, stop) ⇒ StardateInterval
Returns a new instance of StardateInterval.
5 6 7 8 |
# File 'lib/stardate_interval.rb', line 5 def initialize(start, stop) @start = Stardate.new start @stop = Stardate.new stop end |
Instance Attribute Details
#start ⇒ Object
Returns the value of attribute start.
3 4 5 |
# File 'lib/stardate_interval.rb', line 3 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop.
3 4 5 |
# File 'lib/stardate_interval.rb', line 3 def stop @stop end |
Instance Method Details
#-@ ⇒ Object
10 11 12 |
# File 'lib/stardate_interval.rb', line 10 def -@ StardateInterval.new @stop, @start end |
#days ⇒ Object
30 31 32 |
# File 'lib/stardate_interval.rb', line 30 def days years / Stardate.day end |
#hours ⇒ Object
34 35 36 |
# File 'lib/stardate_interval.rb', line 34 def hours years / Stardate.hour end |
#inspect ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/stardate_interval.rb', line 50 def inspect [ '[', @start.to_s, ' - ', @stop.to_s, '] (', to_human, ')' ].join end |
#lifespans ⇒ Object
14 15 16 |
# File 'lib/stardate_interval.rb', line 14 def lifespans years / Stardate.lifespan end |
#milliseconds ⇒ Object
46 47 48 |
# File 'lib/stardate_interval.rb', line 46 def milliseconds years / Stardate.millisecond end |
#minutes ⇒ Object
38 39 40 |
# File 'lib/stardate_interval.rb', line 38 def minutes years / Stardate.minute end |
#months ⇒ Object
22 23 24 |
# File 'lib/stardate_interval.rb', line 22 def months years / Stardate.month end |
#seconds ⇒ Object
42 43 44 |
# File 'lib/stardate_interval.rb', line 42 def seconds years / Stardate.second end |
#to_human(precision = 3) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/stardate_interval.rb', line 62 def to_human(precision = 3) [ :lifespans, :years, :months, :weeks, :days, :hours, :minutes, :seconds, :milliseconds ].each do |scale| x = public_send scale return "%.#{precision}f %s" % [x, scale] if x.abs >= 1 end return "%.#{precision}e seconds" % seconds end |
#weeks ⇒ Object
26 27 28 |
# File 'lib/stardate_interval.rb', line 26 def weeks years / Stardate.week end |
#years ⇒ Object
18 19 20 |
# File 'lib/stardate_interval.rb', line 18 def years @stop.stardate - @start.stardate end |