Class: ADSB::Airplane

Inherits:
Object
  • Object
show all
Defined in:
lib/adsb2kml/airplane.rb

Constant Summary collapse

@@info =
[
  :latitude,
  :longitude,
  :last_heard,
  :speed,
  :vert_rate,
  :track,
  :altitude
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Airplane



27
28
29
30
# File 'lib/adsb2kml/airplane.rb', line 27

def initialize address
  @address = address
  @altitude = "0"
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



21
22
23
# File 'lib/adsb2kml/airplane.rb', line 21

def address
  @address
end

Instance Method Details

#icon(url) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/adsb2kml/airplane.rb', line 63

def icon url
  to_return = KML::Style.new(
    :id => @address + "_style",
    :icon_style => KML::IconStyle.new(
      :heading => @track,
      :icon => KML::Icon.new(
        :href => url
      ),
      :scale => 1.4
    ),
    :label_style => KML::LabelStyle.new(
      :scale => 0.4
    )
  )
end

#infoObject



23
24
25
# File 'lib/adsb2kml/airplane.rb', line 23

def info
  return @@info
end

#merge_with(airplane) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/adsb2kml/airplane.rb', line 32

def merge_with airplane
  if airplane.address != @address then
    return false
  end

  
  @@info.each do |x|
    if ! airplane.send(x).empty? then
      send( x.to_s + "=" , airplane.send(x) )
    end
  end

  return true
end

#placemarkObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/adsb2kml/airplane.rb', line 47

def placemark
  to_return = KML::Placemark.new(
    :name => @address,
    :geometry => KML::Point.new(
      :coordinates => {
        :lat => @latitude,
        :lng => @longitude,
        :alt => @altitude
      }
    ),
    :style_url => "#" + @address + "_style"
  )

  return to_return
end

#time_diffObject



83
84
85
# File 'lib/adsb2kml/airplane.rb', line 83

def time_diff
  return Time.now.to_i - @last_heard.to_i
end

#to_consObject



79
80
81
# File 'lib/adsb2kml/airplane.rb', line 79

def to_cons
  return sprintf $STRING_FORMAT, @address, @latitude, @longitude, @altitude, @speed, @last_heard, time_diff, @track
end