Class: Oldness::Medium
- Inherits:
-
Object
show all
- Defined in:
- lib/oldness/medium.rb
Class Method Summary
collapse
Class Method Details
.began(date, args = {}) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/oldness/medium.rb', line 41
def self.began(date, args={})
@first = Work.new(date, :title => args[:with], :by => args[:by])
def self.first
@first
end
end
|
.first ⇒ Object
43
44
45
|
# File 'lib/oldness/medium.rb', line 43
def self.first
@first
end
|
.inherited(child) ⇒ Object
56
57
58
|
# File 'lib/oldness/medium.rb', line 56
def self.inherited(child)
@descendents << child
end
|
.list(opts = {}) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/oldness/medium.rb', line 48
def self.list(opts={})
if opts[:formatted]
@descendents.collect(&:to_s).sort.inject("") { |l, c| l + c.downcase.sub("oldness::", "")+"\n" }
else
@descendents
end
end
|
.ranges(args = {}) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/oldness/medium.rb', line 7
def self.ranges(args={})
current_date = args[:when] ? args[:when] : Date.today
span = (current_date-first.date)
unit = span/81
ranges = {5 => (first.date..current_date-27*unit),
4 => (current_date-27*unit..current_date-9*unit),
3 => (current_date-9*unit..current_date-3*unit),
2 => (current_date-3*unit..current_date-unit),
1 => (current_date-unit..current_date)}
if args[:formatted]
f_ranges = ""
ranges.each do |stars, range|
f_ranges += ("*" * stars) + (" " * (5-stars)) + ": #{range}\n"
end
f_ranges.chomp
else
ranges
end
end
|
.rate(work_date, args = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/oldness/medium.rb', line 27
def self.rate(work_date, args={})
work_date = parse_date(work_date)
formatted = args[:formatted]
args[:formatted] = nil
rating = ranges(args).find {|key, range| range.cover?(work_date)}[0]
if formatted
"*" * rating
else
rating
end
end
|