Class: Oldness::Work
- Inherits:
-
Object
- Object
- Oldness::Work
- Defined in:
- lib/oldness/work.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
Instance Method Summary collapse
- #by ⇒ Object
-
#initialize(date, args = {}) ⇒ Work
constructor
A new instance of Work.
- #title ⇒ Object
- #to_s ⇒ Object
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
#date ⇒ Object
Returns the value of attribute date.
9 10 11 |
# File 'lib/oldness/work.rb', line 9 def date @date end |
Instance Method Details
#by ⇒ Object
3 4 5 |
# File 'lib/oldness/work.rb', line 3 def by @by ? @by : "Unknown" end |
#title ⇒ Object
6 7 8 |
# File 'lib/oldness/work.rb', line 6 def title @title ? @title : "Untitled" end |
#to_s ⇒ Object
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 |