Class: Kamelopard::Object
- Inherits:
-
Object
- Object
- Kamelopard::Object
- 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. Object IDs are stored in the kml_id attribute, and are prefixed with the value last passed to Kamelopard.id_prefix=, if anything. Note that assigning this prefix will not change the IDs of Kamelopard objects that are already initialized… just ones initialized thereafter.
Direct Known Subclasses
AbstractView, BalloonStyle, ColorStyle, Feature, Geometry, Link, ListStyle, Region, StyleSelector, TimePrimitive, Tour, TourPrimitive, VSRAction
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#kml_id ⇒ Object
Returns the value of attribute kml_id.
-
#master_only ⇒ Object
The master_only attribute determines whether this Object should be included in slave mode KML files, or not.
Class Method Summary collapse
-
.parse(x) ⇒ Object
Abstract function, designed to take an XML node containing a KML object of this type, and parse it into a Kamelopard object.
Instance Method Summary collapse
-
#_alternate_to_kml(*a) ⇒ Object
If this is a master-only object, this function gets called internally in place of the object’s original to_kml method.
-
#change(field, value) ⇒ Object
Generates a <Change> element suitable for changing the given field of an object to the given value.
-
#initialize(options = {}) ⇒ Object
constructor
This constructor looks for values in the options hash that match class attributes, and sets those attributes to the values in the hash.
-
#master_only? ⇒ Boolean
This just makes the Ruby-ism question mark suffix work.
-
#to_kml(elem) ⇒ Object
Returns XML::Node containing this object’s KML.
Constructor Details
#initialize(options = {}) ⇒ Object
This constructor looks for values in the options hash that match class attributes, and sets those attributes to the values in the hash. So a class with an attribute called :when can be set via the constructor by including “:when => some-value” in the options argument to the constructor.
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/kamelopard/classes.rb', line 214 def initialize( = {}) @kml_id = "#{Kamelopard.id_prefix}#{self.class.name.gsub('Kamelopard::', '')}_#{ Kamelopard.get_next_id }" @master_only = false .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
#comment ⇒ Object
Returns the value of attribute comment.
195 196 197 |
# File 'lib/kamelopard/classes.rb', line 195 def comment @comment end |
#kml_id ⇒ Object
Returns the value of attribute kml_id.
194 195 196 |
# File 'lib/kamelopard/classes.rb', line 194 def kml_id @kml_id end |
#master_only ⇒ Object
The master_only attribute determines whether this Object should be included in slave mode KML files, or not. It defaults to false, indicating the Object should be included in KML files of all types. Set it to true to ensure it shows up only in slave mode.
201 202 203 |
# File 'lib/kamelopard/classes.rb', line 201 def master_only @master_only end |
Class Method Details
.parse(x) ⇒ Object
Abstract function, designed to take an XML node containing a KML object of this type, and parse it into a Kamelopard object
205 206 207 |
# File 'lib/kamelopard/classes.rb', line 205 def self.parse(x) raise "Cannot parse a #{self.class.name}" end |
Instance Method Details
#_alternate_to_kml(*a) ⇒ Object
If this is a master-only object, this function gets called internally in place of the object’s original to_kml method
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/kamelopard/classes.rb', line 238 def _alternate_to_kml(*a) if @master_only and ! DocumentHolder.instance.current_document.master_mode Kamelopard.log(:info, 'master/slave', "Because this object is master_only, and we're in slave mode, we're not including object #{self.inspect}") return '' end # XXX There must be a better way to do this, but I don't know what # it is. Running "@original_to_kml_method.call(a)" when the # original method expects multiple arguments interprets the # argument as an array, not as a list of arguments. This of course # makes sense, but I don't know how to get around it. case @original_to_kml_method.parameters.size when 0 return @original_to_kml_method.call when 1 # XXX This bothers me, and I'm unconvinced the calls to # functions with more than one parameter actually work. Why # should I have to pass a[0][0] here and just a[0], a[1], etc. # for larger numbers of parameters, if this were all correct? return @original_to_kml_method.call(a[0][0]) when 2 return @original_to_kml_method.call(a[0], a[1]) when 3 return @original_to_kml_method.call(a[0], a[1], a[2]) else raise "Unsupported number of arguments (#{@original_to_kml_method.arity}) in to_kml function #{@original_to_kml_method}. This is a bug" end end |
#change(field, value) ⇒ Object
Generates a <Change> element suitable for changing the given field of an object to the given value
314 315 316 317 318 319 320 |
# File 'lib/kamelopard/classes.rb', line 314 def change(attributes, values) change = XML::Node.new 'Change' child = XML::Node.new self.class.name child.attributes[:targetId] = @kml_id change << child return change end |
#master_only? ⇒ Boolean
This just makes the Ruby-ism question mark suffix work
290 291 292 |
# File 'lib/kamelopard/classes.rb', line 290 def master_only? return @master_only end |
#to_kml(elem) ⇒ Object
Returns XML::Node containing this object’s KML. Objects should override this method
303 304 305 306 307 308 309 310 |
# File 'lib/kamelopard/classes.rb', line 303 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 |