diff options
author | rhenium <rhenium@rhe.jp> | 2014-07-20 07:01:46 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2014-07-20 07:01:46 +0900 |
commit | cf5ff2bbd144460e3bc704b6b494a6fdd7a49427 (patch) | |
tree | f876252a72fe23f592679b1ec8c1c9d830c4e9dd /app/models/tweet.rb | |
parent | be52ef43eae036ae8c283e116417cac50c511d82 (diff) | |
download | aclog-cf5ff2bbd144460e3bc704b6b494a6fdd7a49427.tar.gz |
web: merge tweets#*_recent into tweets#*_best
Diffstat (limited to 'app/models/tweet.rb')
-rw-r--r-- | app/models/tweet.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 878917a..f831693 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -80,6 +80,25 @@ class Tweet < ActiveRecord::Base tweet.reload end + # Parses /\d+[dwmy]/ style query and returns recent tweets (Relation) in specified period. + # @note When nil or unparsable string are specified, this method does nothing. + # @param [String] param + # @return [ActiveRecord::Relation] + def parse_recent(param) + match = param.to_s.match(/^(\d+)([a-z])$/) + if match + n = match[1].to_i + case match[2] + when "d" then recent(n.days) + when "w" then recent(n.weeks) + when "m" then recent(n.months) + when "y" then recent(n.years) + end + else + self + end + end + # Filters tweets with original query string. # @param [String] query # @return [ActiveRecord::Relation] |