Class: Pragmater::Formatters::General
- Inherits:
-
Object
- Object
- Pragmater::Formatters::General
- Defined in:
- lib/pragmater/formatters/general.rb
Overview
Formats general pragmas in a consistent manner.
Constant Summary collapse
- PATTERN =
/ \A # Start of line. \# # Start of comment. \s? # Space - optional. \w+ # Key - One or more word characters only. : # Delimiter. \s? # Space - optional. [\w-]+ # Value - One or more word or dash characters. \Z # End of line. /x
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(string, pattern: PATTERN) ⇒ General
constructor
A new instance of General.
Constructor Details
#initialize(string, pattern: PATTERN) ⇒ General
Returns a new instance of General.
18 19 20 21 |
# File 'lib/pragmater/formatters/general.rb', line 18 def initialize string, pattern: PATTERN @string = string @pattern = pattern end |
Instance Method Details
#call ⇒ Object
23 24 25 26 27 |
# File 'lib/pragmater/formatters/general.rb', line 23 def call return string unless string.match? pattern string.split(":").then { |key, value| "# #{key.gsub(/\#\s?/, "")}: #{value.strip}" } end |