Class: StardateInterval

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#startObject

Returns the value of attribute start.



3
4
5
# File 'lib/stardate_interval.rb', line 3

def start
  @start
end

#stopObject

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

#daysObject



30
31
32
# File 'lib/stardate_interval.rb', line 30

def days
  years / Stardate.day
end

#hoursObject



34
35
36
# File 'lib/stardate_interval.rb', line 34

def hours
  years / Stardate.hour
end

#inspectObject



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

#lifespansObject



14
15
16
# File 'lib/stardate_interval.rb', line 14

def lifespans
  years / Stardate.lifespan
end

#millisecondsObject



46
47
48
# File 'lib/stardate_interval.rb', line 46

def milliseconds
  years / Stardate.millisecond
end

#minutesObject



38
39
40
# File 'lib/stardate_interval.rb', line 38

def minutes
  years / Stardate.minute
end

#monthsObject



22
23
24
# File 'lib/stardate_interval.rb', line 22

def months
  years / Stardate.month
end

#secondsObject



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

#weeksObject



26
27
28
# File 'lib/stardate_interval.rb', line 26

def weeks
  years / Stardate.week
end

#yearsObject



18
19
20
# File 'lib/stardate_interval.rb', line 18

def years
  @stop.stardate - @start.stardate
end