Class: ColorStyle

Inherits:
KMLObject 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.

Instance Attribute Summary collapse

Attributes inherited from KMLObject

#comment, #id

Instance Method Summary collapse

Constructor Details

#initialize(color, colormode = :normal) ⇒ ColorStyle

Returns a new instance of ColorStyle.



742
743
744
745
746
747
748
# File 'lib/kamelopard/classes.rb', line 742

def initialize(color, colormode = :normal)
    super()
    # Note: color element order is aabbggrr
    @color = color
    validate_colormode colormode
    @colormode = colormode # Can be :normal or :random
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



739
740
741
# File 'lib/kamelopard/classes.rb', line 739

def color
  @color
end

#colormodeObject

Returns the value of attribute colormode.



740
741
742
# File 'lib/kamelopard/classes.rb', line 740

def colormode
  @colormode
end

Instance Method Details

#alphaObject



759
760
761
# File 'lib/kamelopard/classes.rb', line 759

def alpha
    @color[0,1]
end

#alpha=(a) ⇒ Object



763
764
765
# File 'lib/kamelopard/classes.rb', line 763

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

#blueObject



767
768
769
# File 'lib/kamelopard/classes.rb', line 767

def blue
    @color[2,1]
end

#blue=(a) ⇒ Object



771
772
773
# File 'lib/kamelopard/classes.rb', line 771

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

#greenObject



775
776
777
# File 'lib/kamelopard/classes.rb', line 775

def green
    @color[4,1]
end

#green=(a) ⇒ Object



779
780
781
# File 'lib/kamelopard/classes.rb', line 779

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

#redObject



783
784
785
# File 'lib/kamelopard/classes.rb', line 783

def red
    @color[6,1]
end

#red=(a) ⇒ Object



787
788
789
# File 'lib/kamelopard/classes.rb', line 787

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

#to_kml(indent = 0) ⇒ Object



791
792
793
794
795
796
797
# File 'lib/kamelopard/classes.rb', line 791

def to_kml(indent = 0)

    super + <<-colorstyle
#{ ' ' * indent }<color>#{@color}</color>
#{ ' ' * indent }<colorMode>#{@colormode}</colorMode>
    colorstyle
end

#validate_colormode(a) ⇒ Object



750
751
752
# File 'lib/kamelopard/classes.rb', line 750

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