]> git.openstreetmap.org Git - rails.git/blob - app/models/old_node.rb
Move Potlatch configuration to a separate initialiser file.
[rails.git] / app / models / old_node.rb
1 class OldNode < ActiveRecord::Base
2   include GeoRecord
3
4   set_table_name 'nodes'
5   
6   validates_presence_of :user_id, :timestamp
7   validates_inclusion_of :visible, :in => [ true, false ]
8   validates_numericality_of :latitude, :longitude
9   validate :validate_position
10
11   belongs_to :user
12  
13   def validate_position
14     errors.add_to_base("Node is not in the world") unless in_world?
15   end
16
17   def in_world?
18     return false if self.lat < -90 or self.lat > 90
19     return false if self.lon < -180 or self.lon > 180
20     return true
21   end
22
23   def self.from_node(node)
24     old_node = OldNode.new
25     old_node.latitude = node.latitude
26     old_node.longitude = node.longitude
27     old_node.visible = node.visible
28     old_node.tags = node.tags
29     old_node.timestamp = node.timestamp
30     old_node.user_id = node.user_id
31     old_node.id = node.id
32     return old_node
33   end
34
35   def to_xml_node
36     el1 = XML::Node.new 'node'
37     el1['id'] = self.id.to_s
38     el1['lat'] = self.lat.to_s
39     el1['lon'] = self.lon.to_s
40     el1['user'] = self.user.display_name if self.user.data_public?
41
42     Tags.split(self.tags) do |k,v|
43       el2 = XML::Node.new('tag')
44       el2['k'] = k.to_s
45       el2['v'] = v.to_s
46       el1 << el2
47     end
48
49     el1['visible'] = self.visible.to_s
50     el1['timestamp'] = self.timestamp.xmlschema
51     return el1
52   end
53   
54   def tags_as_hash
55     hash = {}
56     Tags.split(self.tags) do |k,v|
57       hash[k] = v
58     end
59     hash
60   end
61
62   # Pretend we're not in any ways
63   def ways
64     return []
65   end
66
67   # Pretend we're not in any relations
68   def containing_relation_members
69     return []
70   end
71 end