Class: ActiveRoad::StreetNumber

Inherits:
Base
  • Object
show all
Defined in:
app/models/active_road/street_number.rb

Defined Under Namespace

Classes: Number

Instance Method Summary collapse

Instance Method Details

#compute_locate_on_roadObject



39
40
41
42
43
# File 'app/models/active_road/street_number.rb', line 39

def compute_locate_on_road
  if stored_location_on_road.nil? and stored_geometry 
    self.location_on_road = road.geometry.locate_point(stored_geometry) 
  end
end

#computed_geometryObject



27
28
29
# File 'app/models/active_road/street_number.rb', line 27

def computed_geometry
  road.at computed_location_on_road
end

#computed_location_on_roadObject

TODO rename into estimated_location_on_road



46
47
48
49
50
51
# File 'app/models/active_road/street_number.rb', line 46

def computed_location_on_road
  if previous and self.next
    number_ratio = (number.to_i - previous.number.to_i) / (self.next.number.to_i - previous.number.to_i).to_f
    previous.location_on_road + number_ratio * (self.next.location_on_road - previous.location_on_road)
  end
end

#geometryObject



23
24
25
# File 'app/models/active_road/street_number.rb', line 23

def geometry
  stored_geometry or computed_geometry
end

#location_on_roadObject



31
32
33
# File 'app/models/active_road/street_number.rb', line 31

def location_on_road
  stored_location_on_road or computed_location_on_road
end

#nextObject



57
58
59
# File 'app/models/active_road/street_number.rb', line 57

def next
  @next ||= road.numbers.find :first, :conditions => ["number > ?", number], :limit => 1, :order => "number"
end

#numberObject



61
62
63
# File 'app/models/active_road/street_number.rb', line 61

def number
  Number.new read_attribute(:number)
end

#previousObject



53
54
55
# File 'app/models/active_road/street_number.rb', line 53

def previous
  @previous ||= road.numbers.find :first, :conditions => ["number < ?", number], :limit => 1, :order => "number desc"
end

#roadObject



10
11
12
# File 'app/models/active_road/street_number.rb', line 10

def road
  @road or physical_road
end

#road=(road) ⇒ Object



13
14
15
# File 'app/models/active_road/street_number.rb', line 13

def road=(road)
  @road ||= road
end

#stored_geometryObject

before_validation :compute_locate_on_road, :on => :create



19
20
21
# File 'app/models/active_road/street_number.rb', line 19

def stored_geometry
  read_attribute :geometry
end

#stored_location_on_roadObject



35
36
37
# File 'app/models/active_road/street_number.rb', line 35

def stored_location_on_road
  read_attribute :location_on_road
end