Class: Kamelopard::Object

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(options = {}) ⇒ Object

Returns a new instance of Object.



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/kamelopard/classes.rb', line 111

def initialize(options = {})
    @kml_id = "#{self.class.name.gsub('Kamelopard::', '')}_#{ Kamelopard.get_next_id }"

    options.each do |k, v|
        method = "#{k}=".to_sym
        if self.respond_to? method then
            self.method(method).call(v)
        else
            raise "Warning: couldn't find attribute for options hash key #{k}"
        end
    end
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



109
110
111
# File 'lib/kamelopard/classes.rb', line 109

def comment
  @comment
end

#kml_idObject

Returns the value of attribute kml_id.



108
109
110
# File 'lib/kamelopard/classes.rb', line 108

def kml_id
  @kml_id
end

Instance Method Details

#change(field, value) ⇒ Object

Generates a <Change> element suitable for changing the given field of an object to the given value



144
145
146
147
148
149
150
151
152
153
# File 'lib/kamelopard/classes.rb', line 144

def change(field, value)
    c = XML::Node.new 'Change'
    o = XML::Node.new self.class.name.sub!(/Kamelopard::/, '')
    o.attributes['targetId'] = self.kml_id
    e = XML::Node.new field
    e.content = value.to_s
    o << e
    c << o
    c
end

#to_kml(elem) ⇒ Object

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



133
134
135
136
137
138
139
140
# File 'lib/kamelopard/classes.rb', line 133

def to_kml(elem)
    elem.attributes['id'] = @kml_id.to_s
    if not @comment.nil? and @comment != '' then
        c = XML::Node.new_comment " #{@comment} "
        elem << c
        return c
    end
end