Class: Fixnum

Inherits:
Object show all
Defined in:
lib/streams/activitystreams.rb

Overview

some syntactic sugar for Fixnums… useful for working with Time .. e.g. updated now - 1.week #updated one week ago

Instance Method Summary collapse

Instance Method Details

#daysObject Also known as: day

treats the fixnum as a representation of a number of days and returns the total number of seconds represented.. e.g. 2.days => 172800



1089
1090
1091
# File 'lib/streams/activitystreams.rb', line 1089

def days
  hours * 24
end

#hoursObject Also known as: hour

treats the fixnum as a representation of a number of hours and returns the total number of seconds represented.. e.g. 2.hours => 7200



1082
1083
1084
# File 'lib/streams/activitystreams.rb', line 1082

def hours
  minutes * 60
end

#millisecondsObject

treats the fixnum as a representation of a number of milliseconds, returns the approximate total number of seconds represented e.g. 1000.milliseconds => 1 fractional seconds are truncated (rounded down)



1061
1062
1063
# File 'lib/streams/activitystreams.rb', line 1061

def milliseconds
  self / 1000
end

#minutesObject Also known as: minute

treats the fixnum as a representation of a number of minutes and returns the total number of seconds represented.. e.g. 2.minutes => 120, 3.minutes => 180



1075
1076
1077
# File 'lib/streams/activitystreams.rb', line 1075

def minutes
  seconds * 60
end

#secondsObject Also known as: second

treats the fixnum as a representation of a number of seconds



1067
1068
1069
# File 'lib/streams/activitystreams.rb', line 1067

def seconds
  self
end

#weeksObject Also known as: week

treats the fixnum as a representatin of a number of weeks and returns the total number of seconds represented.. e.g. 2.weeks => 1209600



1096
1097
1098
# File 'lib/streams/activitystreams.rb', line 1096

def weeks
  days * 7
end

#within?(r) ⇒ Boolean

true if this number is within the given range

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


1052
1053
1054
1055
# File 'lib/streams/activitystreams.rb', line 1052

def within? r
  raise ArgumentError if not r.is_a?Range
  r.include? self
end