1 class Way < ActiveRecord::Base
6 has_many :way_segments, :foreign_key => 'id'
7 has_many :way_tags, :foreign_key => 'id'
9 set_table_name 'current_ways'
11 def self.from_xml(xml, create=false)
18 doc.find('//osm/way').each do |pt|
19 if !create and pt['id'] != '0'
20 way.id = pt['id'].to_i
24 way.timestamp = Time.now
28 way.timestamp = Time.parse(pt['timestamp'])
32 pt.find('tag').each do |tag|
33 way.add_tag_keyval(tag['k'], tag['v'])
36 pt.find('seg').each do |seg|
37 way.add_seg_num(seg['id'])
46 doc = XML::Document.new
47 doc.encoding = 'UTF-8'
48 root = XML::Node.new 'osm'
49 root['version'] = '0.4'
50 root['generator'] = 'OpenStreetMap server'
54 el1 = XML::Node.new 'way'
55 el1['id'] = self.id.to_s
56 el1['visible'] = self.visible.to_s
57 el1['timestamp'] = self.timestamp.xmlschema
59 self.way_segments.each do |seg| # FIXME need to make sure they come back in the right order
60 e = XML::Node.new 'seg'
61 e['id'] = seg.segment_id.to_s
65 self.way_tags.each do |tag|
66 e = XML::Node.new 'tag'
77 @segs = Array.new unless @segs
82 @tags = Hash.new unless @tags
87 @segs = Array.new unless @segs
91 def add_tag_keyval(k, v)
92 @tags = Hash.new unless @tags
101 WayTag.delete_all(['id = ?', self.id])
103 self.tags.each do |k,v|
111 WaySegment.delete_all(['id = ?', self.id])
114 self.segs.each do |n|
123 old_way = OldWay.from_way(self)