Class: Brush

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

Constant Summary collapse

ALLOWED_ATTRIBUTES =
[:fg, :bg, :bold, :underline, :inverse, :blink]
DEFAULT_FG_CODE =
7
DEFAULT_BG_CODE =
0

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Brush

Returns a new instance of Brush.



8
9
10
# File 'lib/asciinema/brush.rb', line 8

def initialize(attributes = {})
  @attributes = attributes.symbolize_keys
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/asciinema/brush.rb', line 12

def ==(other)
  fg == other.fg &&
    bg == other.bg &&
    bold? == other.bold? &&
    underline? == other.underline? &&
    blink? == other.blink?
end

#as_jsonObject



48
49
50
# File 'lib/asciinema/brush.rb', line 48

def as_json(*)
  attributes.slice(*ALLOWED_ATTRIBUTES)
end

#bgObject



24
25
26
# File 'lib/asciinema/brush.rb', line 24

def bg
  inverse? ? fg_code || DEFAULT_FG_CODE : bg_code
end

#blink?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/asciinema/brush.rb', line 40

def blink?
  !!attributes[:blink]
end

#bold?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/asciinema/brush.rb', line 28

def bold?
  !!attributes[:bold]
end

#default?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/asciinema/brush.rb', line 44

def default?
  fg.nil? && bg.nil? && !bold? && !underline? && !inverse? && !blink?
end

#fgObject



20
21
22
# File 'lib/asciinema/brush.rb', line 20

def fg
  inverse? ? bg_code || DEFAULT_BG_CODE : fg_code
end

#inverse?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/asciinema/brush.rb', line 36

def inverse?
  !!attributes[:inverse]
end

#underline?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/asciinema/brush.rb', line 32

def underline?
  !!attributes[:underline]
end