Class: IceCube::Validation

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

Constant Summary collapse

NUMBER_SUFFIX =
['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
SPECIAL_SUFFIX =
{ 11 => 'th', 12 => 'th', 13 => 'th', 14 => 'th' }

Class Method Summary collapse

Class Method Details

.adjust(goal, date) ⇒ Object



8
9
10
11
# File 'lib/ice_cube/validation.rb', line 8

def self.adjust(goal, date)
  return goal if goal.utc_offset == date.utc_offset
  goal - goal.utc_offset + date.utc_offset
end

.nice_numbers(array) ⇒ Object



23
24
25
26
# File 'lib/ice_cube/validation.rb', line 23

def self.nice_numbers(array)
  array.sort!
  self.sentence array.map { |d| nice_number(d) }
end

.sentence(array) ⇒ Object

influences by ActiveSupport’s to_sentence



14
15
16
17
18
19
20
21
# File 'lib/ice_cube/validation.rb', line 14

def self.sentence(array)
  case array.length
  when 0 ; ''
  when 1 ; array[0].to_s
  when 2 ; "#{array[0]} and #{array[1]}"
  else ; "#{array[0...-1].join(', ')}, and #{array[-1]}"
  end
end