Module: Repofetch::Util
- Included in:
- BitbucketCloud, BitbucketCloud, Github, Github, Gitlab, Gitlab, Plugin
- Defined in:
- lib/repofetch/util.rb
Overview
Provides uncategorized utilities.
Instance Method Summary collapse
-
#clean_ansi(str) ⇒ Object
Removes ANSI escape sequences from
str
. -
#default_remote(git) ⇒ Git::Remote
Gets the name of the default remote to use.
-
#default_remote_url(git) ⇒ String
Just wrapper around
default_remote
since this is likely the most common use case (and it’s easier than referencing theGit::Remote
docs to ensure correct usage in each plugin). -
#remove_format_params(str) ⇒ Object
Converts a format string into a plain string (e.g. “%{green}OK” -> “OK”).
Instance Method Details
#clean_ansi(str) ⇒ Object
Removes ANSI escape sequences from str
.
12 13 14 |
# File 'lib/repofetch/util.rb', line 12 def clean_ansi(str) str.gsub("\e", '').gsub(/\[\d+(;\d+)*m/, '') end |
#default_remote(git) ⇒ Git::Remote
Gets the name of the default remote to use.
Will try to pick “origin”, but if that is not found then it will pick the first one found, or nil if there aren’t any available.
24 25 26 27 28 29 |
# File 'lib/repofetch/util.rb', line 24 def default_remote(git) remotes = git.remotes found_remote = remotes.find { |remote| remote.name == 'origin' } found_remote = remotes[0] if found_remote.nil? found_remote end |
#default_remote_url(git) ⇒ String
Just wrapper around default_remote
since this is likely the most common use case (and it’s easier than referencing the Git::Remote
docs to ensure correct usage in each plugin).
38 39 40 |
# File 'lib/repofetch/util.rb', line 38 def default_remote_url(git) default_remote(git)&.url end |
#remove_format_params(str) ⇒ Object
Converts a format string into a plain string (e.g. “%{green}OK” -> “OK”)
7 8 9 |
# File 'lib/repofetch/util.rb', line 7 def remove_format_params(str) str.gsub(/%{[\w\d]+?}/, '') end |