Class: Kamelopard::ColorStyle

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

Overview

Corresponds to KML’s ColorStyle object. Color is stored as an 8-character hex string, with two characters each of alpha, blue, green, and red values, in that order, matching the ordering the KML spec demands.

Direct Known Subclasses

IconStyle, LabelStyle, LineStyle, PolyStyle

Instance Attribute Summary collapse

Attributes inherited from Object

#comment, #kml_id, #master_only

Instance Method Summary collapse

Methods inherited from Object

#_alternate_to_kml, #change, #master_only?, parse

Constructor Details

#initialize(color = nil, options = {}) ⇒ ColorStyle

Returns a new instance of ColorStyle.



1197
1198
1199
1200
# File 'lib/kamelopard/classes.rb', line 1197

def initialize(color = nil, options = {})
    super options
    @color = color unless color.nil?
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



1194
1195
1196
# File 'lib/kamelopard/classes.rb', line 1194

def color
  @color
end

#colorModeObject

Returns the value of attribute colorMode.



1195
1196
1197
# File 'lib/kamelopard/classes.rb', line 1195

def colorMode
  @colorMode
end

Instance Method Details

#alphaObject



1211
1212
1213
# File 'lib/kamelopard/classes.rb', line 1211

def alpha
    @color[0,2]
end

#alpha=(a) ⇒ Object



1215
1216
1217
# File 'lib/kamelopard/classes.rb', line 1215

def alpha=(a)
    @color[0,2] = a
end

#blueObject



1219
1220
1221
# File 'lib/kamelopard/classes.rb', line 1219

def blue
    @color[2,2]
end

#blue=(a) ⇒ Object



1223
1224
1225
# File 'lib/kamelopard/classes.rb', line 1223

def blue=(a)
    @color[2,2] = a
end

#greenObject



1227
1228
1229
# File 'lib/kamelopard/classes.rb', line 1227

def green
    @color[4,2]
end

#green=(a) ⇒ Object



1231
1232
1233
# File 'lib/kamelopard/classes.rb', line 1231

def green=(a)
    @color[4,2] = a
end

#redObject



1235
1236
1237
# File 'lib/kamelopard/classes.rb', line 1235

def red
    @color[6,2]
end

#red=(a) ⇒ Object



1239
1240
1241
# File 'lib/kamelopard/classes.rb', line 1239

def red=(a)
    @color[6,2] = a
end

#to_kml(elem = nil) ⇒ Object



1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
# File 'lib/kamelopard/classes.rb', line 1243

def to_kml(elem = nil)
    k = elem.nil? ? XML::Node.new('ColorStyle') : elem
    super k
    e = XML::Node.new 'color'
    e << @color
    k << e
    e = XML::Node.new 'colorMode'
    e << @colorMode
    k << e
    k
end

#validate_colorMode(a) ⇒ Object



1202
1203
1204
# File 'lib/kamelopard/classes.rb', line 1202

def validate_colorMode(a)
    raise "colorMode must be either \"normal\" or \"random\"" unless a == :normal or a == :random
end