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.

Direct Known Subclasses

BalloonStyle, IconStyle, LabelStyle, LineStyle, ListStyle, PolyStyle

Instance Attribute Summary (collapse)

Attributes inherited from KMLObject

#comment, #id

Instance Method Summary (collapse)

Constructor Details

- (ColorStyle) initialize(color, colormode = :normal)

A new instance of ColorStyle



670
671
672
673
674
675
676
# File 'lib/kamelopard/classes.rb', line 670

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

- (Object) color

Returns the value of attribute color



667
668
669
# File 'lib/kamelopard/classes.rb', line 667

def color
  @color
end

- (Object) colormode

Returns the value of attribute colormode



668
669
670
# File 'lib/kamelopard/classes.rb', line 668

def colormode
  @colormode
end

Instance Method Details

- (Object) alpha



687
688
689
# File 'lib/kamelopard/classes.rb', line 687

def alpha
    @color[0,1]
end

- (Object) alpha=(a)



691
692
693
# File 'lib/kamelopard/classes.rb', line 691

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

- (Object) blue



695
696
697
# File 'lib/kamelopard/classes.rb', line 695

def blue
    @color[2,1]
end

- (Object) blue=(a)



699
700
701
# File 'lib/kamelopard/classes.rb', line 699

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

- (Object) green



703
704
705
# File 'lib/kamelopard/classes.rb', line 703

def green
    @color[4,1]
end

- (Object) green=(a)



707
708
709
# File 'lib/kamelopard/classes.rb', line 707

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

- (Object) red



711
712
713
# File 'lib/kamelopard/classes.rb', line 711

def red
    @color[6,1]
end

- (Object) red=(a)



715
716
717
# File 'lib/kamelopard/classes.rb', line 715

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

- (Object) to_kml(indent = 0)



719
720
721
722
723
724
725
# File 'lib/kamelopard/classes.rb', line 719

def to_kml(indent = 0)

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

- (Object) validate_colormode(a)



678
679
680
# File 'lib/kamelopard/classes.rb', line 678

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