Class: Eskimo::ASCII::Highlight
- Defined in:
- gems/eskimo-ascii/lib/eskimo/ascii/components/highlight.rb
Overview
Highlight a substring with ASCII arrows.
Highlight.new(pattern: /lol/) do “- include: lol://file.yml” end # => “- include: lol://file.yml” # ^^^
Instance Attribute Summary collapse
-
#pastel ⇒ Object
readonly
Returns the value of attribute pastel.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
-
#initialize(pattern:, style: [:red, :bold, :underline], &children) ⇒ Highlight
constructor
A new instance of Highlight.
- #render ⇒ Object
Constructor Details
#initialize(pattern:, style: [:red, :bold, :underline], &children) ⇒ Highlight
Returns a new instance of Highlight
15 16 17 18 19 20 21 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/highlight.rb', line 15 def initialize(pattern:, style: [:red, :bold, :underline], &children) @pastel = Pastel.new @pattern = pattern @style = style super(&children) end |
Instance Attribute Details
#pastel ⇒ Object (readonly)
Returns the value of attribute pastel
13 14 15 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/highlight.rb', line 13 def pastel @pastel end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern
13 14 15 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/highlight.rb', line 13 def pattern @pattern end |
#style ⇒ Object (readonly)
Returns the value of attribute style
13 14 15 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/highlight.rb', line 13 def style @style end |
Instance Method Details
#render ⇒ Object
23 24 25 26 27 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/highlight.rb', line 23 def render(**) super.sub(pattern) do |substring| pastel.decorate(substring, *style) end end |