Class: Oldness::Work

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, args = {}) ⇒ Work

Returns a new instance of Work.



10
11
12
# File 'lib/oldness/work.rb', line 10

def initialize(date, args={})
  @date, @title, @by = date, args[:title], args[:by]
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



9
10
11
# File 'lib/oldness/work.rb', line 9

def date
  @date
end

Instance Method Details

#byObject



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

def by
  @by ? @by : "Unknown"
end

#titleObject



6
7
8
# File 'lib/oldness/work.rb', line 6

def title
  @title ? @title : "Untitled"
end

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oldness/work.rb', line 13

def to_s
  if date.yday == 1
    if date.year < 0
      f_date = (date.year * -1).to_s + "BC"
    else
      f_date = "#{date.year}"
    end
  elsif date.mday == 1
    f_date = date.strftime("%B %Y")
  else
    f_date = date.strftime("%B %-d, %Y")
  end
  str = "#{title} (#{f_date})"
  if @by
    str += ", by #{@by}"
  end
  str
end