2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/helpers/watchtower_helper.rb', line 2
def short_distance(timestamp)
result = ""
format = /^(less than|about|over)* *(a|\d+) *(.+)$/
to_parse = distance_of_time_in_words_to_now(timestamp)
return to_parse if (parsed = to_parse.scan(format).flatten.compact).empty?
measurement = parsed.pop
amount = parsed.pop
approximation = parsed.pop unless parsed.empty?
if approximation
result << case approximation
when "less than"
"<"
when "about"
"≈"
when "over"
">"
end
end
result << ((amount =~ /a/).nil? ? amount : "1")
result << ((measurement =~ /month/).nil? ? measurement.strip.split(//).first : "mo")
result
end
|