Class: Lantus::AwesomeDate

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

Instance Method Summary collapse

Constructor Details

#initialize(d) ⇒ AwesomeDate

Returns a new instance of AwesomeDate.



5
6
7
# File 'lib/lantus/awesome_date.rb', line 5

def initialize d
  @time = Time.parse d
end

Instance Method Details

#cardinal_dayObject



28
29
30
# File 'lib/lantus/awesome_date.rb', line 28

def cardinal_day
  @time.strftime("%-d").to_i
end

#dateObject



20
21
22
# File 'lib/lantus/awesome_date.rb', line 20

def date
  @time.strftime "%F"
end

#dayObject



24
25
26
# File 'lib/lantus/awesome_date.rb', line 24

def day
  @time.strftime("%A").downcase
end

#monthObject



39
40
41
# File 'lib/lantus/awesome_date.rb', line 39

def month
  @time.strftime("%B").downcase
end

#nice_dateObject



43
44
45
46
47
48
49
# File 'lib/lantus/awesome_date.rb', line 43

def nice_date
  "%s %s %s" % [
    self.day,
    self.month,
    self.ordinal_day
  ]
end

#ordinal(cardinal) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/lantus/awesome_date.rb', line 51

def ordinal cardinal
  last_digit = cardinal % 10
  case last_digit
    when 1
      "st"
    when 2
      "nd"
    when 3
      "rd"
    else
      "th"
  end
end

#ordinal_dayObject



32
33
34
35
36
37
# File 'lib/lantus/awesome_date.rb', line 32

def ordinal_day
  "%d%s" % [
    self.cardinal_day,
    self.ordinal(self.cardinal_day)
  ]
end

#short_timeObject



16
17
18
# File 'lib/lantus/awesome_date.rb', line 16

def short_time
  @time.strftime "%H:%M"
end

#timeObject



9
10
11
12
13
14
# File 'lib/lantus/awesome_date.rb', line 9

def time
  "%s %s" % [
    @time.strftime("%T"),
    @time.zone
  ]
end