1 class MapBug < ActiveRecord::Base
4 has_many :comments, :class_name => "MapBugComment",
5 :foreign_key => :bug_id,
7 :conditions => "visible = true AND body IS NOT NULL"
9 validates_presence_of :id, :on => :update
10 validates_uniqueness_of :id
11 validates_numericality_of :latitude, :only_integer => true
12 validates_numericality_of :longitude, :only_integer => true
13 validates_presence_of :closed_at if :status == "closed"
14 validates_inclusion_of :status, :in => ["open", "closed", "hidden"]
16 def self.create_bug(lat, lon)
17 bug = MapBug.new(:lat => lat, :lon => lon, :status => "open")
18 raise OSM::APIBadUserInput.new("The node is outside this world") unless bug.in_world?
24 self.status = "closed"
25 self.closed_at = Time.now.getutc
30 def flatten_comment(separator_char, upto_timestamp = :nil)
33 self.comments.each do |comment|
34 next if upto_timestamp != :nil and comment.created_at > upto_timestamp
35 resp += (comment_no == 1 ? "" : separator_char)
36 resp += comment.body if comment.body
38 resp += comment.author_name if comment.author_name
39 resp += " " + comment.created_at.to_s + " ]"
47 return status != "hidden"
51 self.comments.first.author
55 self.comments.first.author_ip
59 self.comments.first.author_id
63 self.comments.first.author_name