Class: Hansi::Special
Instance Method Summary collapse
-
#initialize(ansi, css = nil) ⇒ Special
constructor
A new instance of Special.
- #inspect ⇒ Object
- #to_ansi(mode: Hansi.mode, **options) ⇒ Object
- #to_css_rule ⇒ Object
Methods inherited from AnsiCode
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
#inspect ⇒ Object
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, **) mode &&= mode[/\d+/].to_i unless mode.is_a? Integer @ansi if mode > 1 end |
#to_css_rule ⇒ Object
12 13 14 |
# File 'lib/hansi/special.rb', line 12 def to_css_rule @css || super end |