Class: Grepresent::FormatterRule
- Inherits:
-
Object
- Object
- Grepresent::FormatterRule
- Defined in:
- lib/grepresent/formatter_rule.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #apply(string) ⇒ Object
- #formats ⇒ Object
-
#initialize(pattern, format) ⇒ FormatterRule
constructor
A new instance of FormatterRule.
Constructor Details
#initialize(pattern, format) ⇒ FormatterRule
Returns a new instance of FormatterRule.
6 7 8 9 |
# File 'lib/grepresent/formatter_rule.rb', line 6 def initialize(pattern, format) @pattern = Regexp.new(pattern) @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'lib/grepresent/formatter_rule.rb', line 4 def format @format end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
4 5 6 |
# File 'lib/grepresent/formatter_rule.rb', line 4 def pattern @pattern end |
Instance Method Details
#apply(string) ⇒ Object
11 12 13 14 15 |
# File 'lib/grepresent/formatter_rule.rb', line 11 def apply(string) string.gsub(pattern) do |m| "#{ formats }#{ m }#{ Term::ANSIColor.reset }" end end |
#formats ⇒ Object
17 18 19 |
# File 'lib/grepresent/formatter_rule.rb', line 17 def formats format.split(',').map { |f| Term::ANSIColor.send(f) }.join('') end |