Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- fastlane_core/lib/fastlane_core/core_ext/shellwords.rb,
fastlane/lib/fastlane/action.rb,
fastlane_core/lib/fastlane_core/ui/interface.rb,
fastlane_core/lib/fastlane_core/string_filters.rb,
fastlane_core/lib/fastlane_core/core_ext/string.rb,
spaceship/lib/spaceship/tunes/language_converter.rb,
fastlane_core/lib/fastlane_core/ui/disable_colors.rb
Overview
Here be monkey patches
Helpers collapse
Instance Method Summary collapse
- #dedent! ⇒ Object
- #fastlane_class ⇒ Object
- #fastlane_module ⇒ Object
- #fastlane_underscore ⇒ Object
- #markdown_clean_heredoc! ⇒ Object
- #markdown_details(is_first) ⇒ Object
- #markdown_list(is_first = false) ⇒ Object
- #markdown_preserve_newlines ⇒ Object
- #markdown_sample(is_first = false) ⇒ Object
-
#middle_truncate(length = 20, options = {}) ⇒ Object
Base taken from: stackoverflow.com/a/12202205/1945875.
- #remove_markdown ⇒ Object
-
#shellescape ⇒ Object
CrossplatformShellwords.
- #to_full_language ⇒ Object
- #to_itc_locale ⇒ Object
- #to_language_code ⇒ Object
-
#truncate(truncate_at, options = {}) ⇒ Object
Truncates a given
text
after a givenlength
iftext
is longer thanlength
:. -
#wordwrap(length = 80) ⇒ Object
Base taken from: www.ruby-forum.com/topic/57805.
Instance Method Details
#dedent! ⇒ Object
185 186 187 188 189 |
# File 'fastlane/lib/fastlane/action.rb', line 185 def dedent! first_line_indent = self.match(/^\s*/)[0] self.gsub!(/^#{first_line_indent}/, "") end |
#deprecated ⇒ Object
202 203 204 |
# File 'fastlane_core/lib/fastlane_core/ui/interface.rb', line 202 def deprecated self.bold.blue end |
#fastlane_class ⇒ Object
2 3 4 |
# File 'fastlane_core/lib/fastlane_core/core_ext/string.rb', line 2 def fastlane_class split('_').collect!(&:capitalize).join end |
#fastlane_module ⇒ Object
6 7 8 |
# File 'fastlane_core/lib/fastlane_core/core_ext/string.rb', line 6 def fastlane_module self == "pem" ? 'PEM' : self.fastlane_class end |
#fastlane_underscore ⇒ Object
10 11 12 13 14 15 16 |
# File 'fastlane_core/lib/fastlane_core/core_ext/string.rb', line 10 def fastlane_underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |
#markdown_clean_heredoc! ⇒ Object
180 181 182 183 |
# File 'fastlane/lib/fastlane/action.rb', line 180 def markdown_clean_heredoc! self.chomp! # remove the last new line added by the heredoc self.dedent! # remove the leading whitespace (similar to the squiggly heredoc `<<~`) end |
#markdown_details(is_first) ⇒ Object
174 175 176 177 178 |
# File 'fastlane/lib/fastlane/action.rb', line 174 def markdown_details(is_first) self.prepend("\n") unless is_first self << "\n>" # continue the quote self.markdown_preserve_newlines end |
#markdown_list(is_first = false) ⇒ Object
167 168 169 170 171 172 |
# File 'fastlane/lib/fastlane/action.rb', line 167 def markdown_list(is_first = false) self.markdown_clean_heredoc! self.gsub!(/^/, "- ") # add list dashes self.prepend(">") unless is_first # the empty line that will be added breaks the quote self.markdown_details(is_first) end |
#markdown_preserve_newlines ⇒ Object
158 159 160 |
# File 'fastlane/lib/fastlane/action.rb', line 158 def markdown_preserve_newlines self.gsub(/(\n|$)/, '|\1') # prepend new lines with "|" so the erb template knows *not* to replace them with "<br>"s end |
#markdown_sample(is_first = false) ⇒ Object
162 163 164 165 |
# File 'fastlane/lib/fastlane/action.rb', line 162 def markdown_sample(is_first = false) self.markdown_clean_heredoc! self.markdown_details(is_first) end |
#middle_truncate(length = 20, options = {}) ⇒ Object
Base taken from: stackoverflow.com/a/12202205/1945875
43 44 45 46 47 48 49 50 |
# File 'fastlane_core/lib/fastlane_core/string_filters.rb', line 43 def middle_truncate(length = 20, = {}) omission = [:omission] || '...' return self if self.length <= length + omission.length return self[0..length] if length < omission.length len = (length - omission.length) / 2 s_len = len - length % 2 self[0..s_len] + omission + self[self.length - len..self.length] end |
#remove_markdown ⇒ Object
191 192 193 194 195 196 197 |
# File 'fastlane/lib/fastlane/action.rb', line 191 def remove_markdown string = self.gsub(/^>/, "") # remove Markdown quotes string = string.gsub(/\[http[^\]]+\]\(([^)]+)\)/, '\1 🔗') # remove Markdown links string = string.gsub(/\[([^\]]+)\]\(([^\)]+)\)/, '"\1" (\2 🔗)') # remove Markdown links with custom text string = string.gsub("|", "") # remove new line preserve markers return string end |
#shellescape ⇒ Object
CrossplatformShellwords
8 9 10 |
# File 'fastlane_core/lib/fastlane_core/core_ext/shellwords.rb', line 8 def shellescape CrossplatformShellwords.shellescape(self) end |
#to_full_language ⇒ Object
62 63 64 |
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 62 def to_full_language Spaceship::Tunes::LanguageConverter.from_standard_to_itc(self) end |
#to_itc_locale ⇒ Object
58 59 60 |
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 58 def to_itc_locale Spaceship::Tunes::LanguageConverter.from_standard_to_itc_locale(self) end |
#to_language_code ⇒ Object
54 55 56 |
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 54 def to_language_code Spaceship::Tunes::LanguageConverter.from_itc_to_standard(self) end |
#truncate(truncate_at, options = {}) ⇒ Object
Truncates a given text
after a given length
if text
is longer than length
:
'Once upon a time, in a world far, far away'.truncate(28)
# => "Once upon a time, in a wo..."
Pass a string or regexp :separator
to truncate text
at a natural break:
'Once upon a time, in a world far, far away'.truncate(28, separator: ' ')
# => "Once upon a time, in a..."
'Once upon a time, in a world far, far away'.truncate(28, separator: /\s/)
# => "Once upon a time, in a..."
The last characters will be replaced with the :omission
string (defaults to “…”) for a total length not exceeding length
:
'And they found that many people were sleeping better.'.truncate(25, omission: '... (continued)')
# => "And they f... (continued)"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'fastlane_core/lib/fastlane_core/string_filters.rb', line 20 def truncate(truncate_at, = {}) return dup unless length > truncate_at omission = [:omission] || '...' length_with_room_for_omission = truncate_at - omission.length stop = \ if [:separator] rindex([:separator], length_with_room_for_omission) || length_with_room_for_omission else length_with_room_for_omission end "#{self[0, stop]}#{omission}" end |
#wordwrap(length = 80) ⇒ Object
Base taken from: www.ruby-forum.com/topic/57805
36 37 38 39 40 |
# File 'fastlane_core/lib/fastlane_core/string_filters.rb', line 36 def wordwrap(length = 80) return [] if length == 0 self.gsub!(/(\S{#{length}})(?=\S)/, '\1 ') self.scan(/.{1,#{length}}(?:\s+|$)/) end |