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

Instance Method Summary collapse

Methods inherited from Object

#change

Constructor Details

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

Returns a new instance of ColorStyle.



837
838
839
840
# File 'lib/kamelopard/classes.rb', line 837

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

Instance Attribute Details

#colorObject

Returns the value of attribute color.



834
835
836
# File 'lib/kamelopard/classes.rb', line 834

def color
  @color
end

#colorModeObject

Returns the value of attribute colorMode.



835
836
837
# File 'lib/kamelopard/classes.rb', line 835

def colorMode
  @colorMode
end

Instance Method Details

#alphaObject



851
852
853
# File 'lib/kamelopard/classes.rb', line 851

def alpha
    @color[0,2]
end

#alpha=(a) ⇒ Object



855
856
857
# File 'lib/kamelopard/classes.rb', line 855

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

#blueObject



859
860
861
# File 'lib/kamelopard/classes.rb', line 859

def blue
    @color[2,2]
end

#blue=(a) ⇒ Object



863
864
865
# File 'lib/kamelopard/classes.rb', line 863

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

#greenObject



867
868
869
# File 'lib/kamelopard/classes.rb', line 867

def green
    @color[4,2]
end

#green=(a) ⇒ Object



871
872
873
# File 'lib/kamelopard/classes.rb', line 871

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

#redObject



875
876
877
# File 'lib/kamelopard/classes.rb', line 875

def red
    @color[6,2]
end

#red=(a) ⇒ Object



879
880
881
# File 'lib/kamelopard/classes.rb', line 879

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

#to_kml(elem = nil) ⇒ Object



883
884
885
886
887
888
889
890
891
892
893
# File 'lib/kamelopard/classes.rb', line 883

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



842
843
844
# File 'lib/kamelopard/classes.rb', line 842

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