Class: Hansi::Special

Inherits:
AnsiCode show all
Defined in:
lib/hansi/special.rb

Instance Method Summary collapse

Methods inherited from AnsiCode

#to_ansi_code, #to_css

Constructor Details

#initialize(ansi, css = nil) ⇒ Special

Returns a new instance of Special.



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

def initialize(ansi, css = nil)
  ansi  = "\e[#{ansi}m" unless ansi.is_a? String and ansi.start_with? "\e"
  css   = css.map { |a| a.map { |v| Symbol === v ? v.to_s.tr('_','-') : v.to_s }.join(': ') } if css.is_a? Hash
  css   = css.join("; ") if css.is_a? Array
  css   = css + ";" if css and not css.end_with? ";"
  @ansi = ansi
  @css  = css
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/hansi/special.rb', line 21

def inspect
  "<%p:%p>" % [self.class, @ansi]
end

#to_ansi(mode: Hansi.mode, **options) ⇒ Object



16
17
18
19
# File 'lib/hansi/special.rb', line 16

def to_ansi(mode: Hansi.mode, **options)
  mode &&= mode[/\d+/].to_i unless mode.is_a? Integer
  @ansi if mode > 1
end

#to_css_ruleObject



12
13
14
# File 'lib/hansi/special.rb', line 12

def to_css_rule
  @css || super
end