Class: Brush
- Inherits:
-
Object
- Object
- Brush
- 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
- #==(other) ⇒ Object
- #as_json ⇒ Object
- #bg ⇒ Object
- #blink? ⇒ Boolean
- #bold? ⇒ Boolean
- #default? ⇒ Boolean
- #fg ⇒ Object
-
#initialize(attributes = {}) ⇒ Brush
constructor
A new instance of Brush.
- #inverse? ⇒ Boolean
- #underline? ⇒ Boolean
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_json ⇒ Object
48 49 50 |
# File 'lib/asciinema/brush.rb', line 48 def as_json(*) attributes.slice(*ALLOWED_ATTRIBUTES) end |
#bg ⇒ Object
24 25 26 |
# File 'lib/asciinema/brush.rb', line 24 def bg inverse? ? fg_code || DEFAULT_FG_CODE : bg_code end |
#blink? ⇒ Boolean
40 41 42 |
# File 'lib/asciinema/brush.rb', line 40 def blink? !!attributes[:blink] end |
#bold? ⇒ Boolean
28 29 30 |
# File 'lib/asciinema/brush.rb', line 28 def bold? !!attributes[:bold] end |
#default? ⇒ Boolean
44 45 46 |
# File 'lib/asciinema/brush.rb', line 44 def default? fg.nil? && bg.nil? && !bold? && !underline? && !inverse? && !blink? end |
#fg ⇒ Object
20 21 22 |
# File 'lib/asciinema/brush.rb', line 20 def fg inverse? ? bg_code || DEFAULT_BG_CODE : fg_code end |
#inverse? ⇒ Boolean
36 37 38 |
# File 'lib/asciinema/brush.rb', line 36 def inverse? !!attributes[:inverse] end |
#underline? ⇒ Boolean
32 33 34 |
# File 'lib/asciinema/brush.rb', line 32 def underline? !!attributes[:underline] end |