Sha256: 0dcc9d308a595b0678a4fe4f2d11c34fe03ff903e1dc1fbd523247a871850988
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module Pragmater # Formats pragma comments in a consistent manner. class Formatter def self.shebang_format %r(\A\#\!\s?\/.*ruby\Z) end def self.pragma_format / \A # Start of line. \# # Start of comment. \s? # Space - optional. \w+ # Key - 1 or more word characters only. \: # Key and value delimiter. \s? # Space - optional. [\w\-]+ # Value - 1 or more word or dash characters. \Z # End of line. /x end def self.valid_formats Regexp.union shebang_format, pragma_format end def initialize string @string = string end def format_shebang return string unless string.match?(self.class.shebang_format) _, path = string.split "!" "#! #{path.strip}" end def format_pragma return string unless string.match?(self.class.pragma_format) key, value = string.split ":" "# #{key.gsub(/\#\s?/, "")}: #{value.strip}" end def format case string when self.class.shebang_format then format_shebang when self.class.pragma_format then format_pragma else string end end private attr_reader :string end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pragmater-3.1.0 | lib/pragmater/formatter.rb |
pragmater-3.0.0 | lib/pragmater/formatter.rb |