Class: Headline
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Headline
- Defined in:
- app/models/headline.rb
Overview
Motiro - A project tracking tool
Copyright (C) 2006-2008 Thiago Arrais
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Class Method Summary collapse
- .find_with_reporter_and_rid(reporter_name, rid) ⇒ Object
- .latest(num, reporter) ⇒ Object
- .latest_filled_headline_rid_for(reporter) ⇒ Object
Instance Method Summary collapse
-
#cache ⇒ Object
Saves the headline locally, if it isn’t already cached.
- #cached? ⇒ Boolean
- #description(translator = Translator.default) ⇒ Object
- #filled? ⇒ Boolean
- #happened_at=(date_components) ⇒ Object
-
#initialize(params = {}) ⇒ Headline
constructor
A new instance of Headline.
- #title(translator = Translator.default) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Headline
Returns a new instance of Headline.
21 22 23 24 25 26 27 28 |
# File 'app/models/headline.rb', line 21 def initialize(params={}) params[:description] ||= '' if !params[:title].nil? then params[:description] = params[:title] + "\n\n" + params[:description] params.delete :title end super(params) end |
Class Method Details
.find_with_reporter_and_rid(reporter_name, rid) ⇒ Object
47 48 49 50 51 |
# File 'app/models/headline.rb', line 47 def self.find_with_reporter_and_rid(reporter_name, rid) find(:first, :conditions => ["reported_by = ? and rid = ?", reporter_name, rid]) end |
.latest(num, reporter) ⇒ Object
30 31 32 33 34 35 |
# File 'app/models/headline.rb', line 30 def self.latest(num, reporter) find(:all, :conditions => ["reported_by = ?", reporter], :order => 'happened_at DESC', :limit => num) end |
.latest_filled_headline_rid_for(reporter) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/models/headline.rb', line 37 def self.latest_filled_headline_rid_for(reporter) hls = find(:all, :conditions => ["reported_by = ?", reporter], :order => 'happened_at DESC') hls.each do |hl| return hl.rid if hl.filled? end nil end |
Instance Method Details
#cache ⇒ Object
Saves the headline locally, if it isn’t already cached
74 75 76 77 78 79 |
# File 'app/models/headline.rb', line 74 def cache unless self.cached? self.class.destroy_all similar_to_self self.save end end |
#cached? ⇒ Boolean
81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/headline.rb', line 81 def cached? cached_lines = Headline.find(:all, :conditions => similar_to_self) return false if cached_lines.empty? cached_lines.each do |hl| return true if hl.filled? end return false end |
#description(translator = Translator.default) ⇒ Object
69 70 71 |
# File 'app/models/headline.rb', line 69 def description(translator=Translator.default) translator.localize(self[:description]) end |
#filled? ⇒ Boolean
93 94 95 96 97 98 99 |
# File 'app/models/headline.rb', line 93 def filled? self.changes.each do |c| return false if !c.filled? end return true end |
#happened_at=(date_components) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/models/headline.rb', line 53 def happened_at=(date_components) if date_components.is_a? Time self[:happened_at] = date_components else year, month, day, hour, min, sec = date_components self[:happened_at] = Time.local(year, month, day, hour, min, sec) end end |
#title(translator = Translator.default) ⇒ Object
62 63 64 65 66 67 |
# File 'app/models/headline.rb', line 62 def title(translator=Translator.default) answer = description(translator). split($/). first || '' answer.strip end |