Class: Style

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

Constant Summary collapse

@@re_color =
Regexp.new(/^#(([0-9a-fA-F]{6})|([0-9a-fA-F]{3}))$/)

Instance Method Summary collapse

Constructor Details

#initializeStyle

Returns a new instance of Style.



3
4
5
6
7
8
9
10
# File 'lib/style.rb', line 3

def initialize
    @colors = {
        :bg     => "#202020",
        :fg     => "#757575",
        :bg_hi  => "#303030",
        :fg_hi  => "#FECF35"
    }
end

Instance Method Details

#color(color) ⇒ Object



22
23
24
25
26
27
# File 'lib/style.rb', line 22

def color color
    unless @colors.keys.include? color
        raise ArgumentError, "Invalid key!"
    end
    @colors[color]
end

#fontObject



38
39
40
# File 'lib/style.rb', line 38

def font
    @font
end

#font=(font) ⇒ Object



29
30
31
# File 'lib/style.rb', line 29

def font= font
    @font = font
end

#set_color(color, value) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/style.rb', line 12

def set_color color, value
    unless @colors.keys.include? color
        raise ArgumentError, "Invalid key!"
    end
    unless @@re_color.match value
        raise ArgumentError, "Invalid color string!"
    end
    @colors[color] = value
end

#to_sObject



32
33
34
35
36
# File 'lib/style.rb', line 32

def to_s
    string = ""
    string = @font unless @font.nil?
    string += " #{@colors}"
end