Class: Range

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

Instance Method Summary collapse

Instance Method Details

#to_daysObject

Takes a range and converts it to an array of days

(Time.now..7.days.from_now).to_days



42
43
44
45
46
47
48
49
50
51
# File 'lib/timemaster/extensions.rb', line 42

def to_days
  return if first > last
  arr = []
  time = first
  while time <= last
    arr << time
    time += 1.day
  end
  return arr
end

#to_hoursObject

Takes a range and converts it to an array of hours

(Time.now..1.day.from_now).to_hours



58
59
60
61
62
63
64
65
66
67
# File 'lib/timemaster/extensions.rb', line 58

def to_hours
  return if first > last
  arr = []
  time = first
  while time <= last
    arr << time
    time += 1.hour
  end
  return arr
end

#to_minutesObject

Takes a range and converts it to an array of minutes

(Time.now..1.day.from_now).to_hours



74
75
76
77
78
79
80
81
82
83
# File 'lib/timemaster/extensions.rb', line 74

def to_minutes
  return if first > last
  arr = []
  time = first
  while time <= last
    arr << time
    time += 1.minute
  end
  return arr
end

#to_monthsObject

Takes a range and converts it to an array of months

(Time.now..1.day.from_now).to_hours



27
28
29
30
31
32
33
34
35
36
# File 'lib/timemaster/extensions.rb', line 27

def to_months
  return if first > last
  arr = []
  time = first
  while time <= last
    arr << time
    time += 1.month
  end
  return arr
end