Class: KMLObject

Inherits:
Object
  • Object
show all
Defined in:
lib/kamelopard/classes.rb

Overview

Base class for all Kamelopard objects. Manages object ID and a single comment string associated with the object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment = nil) ⇒ KMLObject

Returns a new instance of KMLObject.



87
88
89
90
# File 'lib/kamelopard/classes.rb', line 87

def initialize(comment = nil)
    @id = "#{self.class.name}_#{ get_next_id }"
    @comment = comment.gsub(/</, '&lt;') unless comment.nil?
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



85
86
87
# File 'lib/kamelopard/classes.rb', line 85

def comment
  @comment
end

#idObject

Returns the value of attribute id.



85
86
87
# File 'lib/kamelopard/classes.rb', line 85

def id
  @id
end

Instance Method Details

#to_kml(indent = 0) ⇒ Object

Returns KML string for this object. Objects should override this method



93
94
95
96
97
98
99
# File 'lib/kamelopard/classes.rb', line 93

def to_kml(indent = 0)
    if @comment.nil? or @comment == '' then
        ''
    else
        "#{ ' ' * indent }<!-- #{ @comment } -->\n"
    end
end