class String

Here be monkey patches

Public Instance Methods

dedent!() click to toggle source
# File fastlane/lib/fastlane/action.rb, line 185
def dedent!
  first_line_indent = self.match(/^\s*/)[0]

  self.gsub!(/^#{first_line_indent}/, "")
end
deprecated() click to toggle source
# File fastlane_core/lib/fastlane_core/ui/interface.rb, line 202
def deprecated
  self.bold.blue
end
fastlane_class() click to toggle source
# File fastlane_core/lib/fastlane_core/core_ext/string.rb, line 2
def fastlane_class
  split('_').collect!(&:capitalize).join
end
fastlane_module() click to toggle source
# File fastlane_core/lib/fastlane_core/core_ext/string.rb, line 6
def fastlane_module
  self == "pem" ? 'PEM' : self.fastlane_class
end
fastlane_underscore() click to toggle source
# 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!() click to toggle source
# 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 squigly heredoc `<<~`)
end
markdown_details(is_first) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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 = {}) click to toggle source

Base taken from: stackoverflow.com/a/12202205/1945875

# File fastlane_core/lib/fastlane_core/string_filters.rb, line 43
def middle_truncate(length = 20, options = {})
  omission = options[: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() click to toggle source
# 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() click to toggle source

CrossplatformShellwords

# File fastlane_core/lib/fastlane_core/core_ext/shellwords.rb, line 8
def shellescape
  CrossplatformShellwords.shellescape(self)
end
to_full_language() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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 = {}) click to toggle source

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(27)
# => "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(27, separator: ' ')
# => "Once upon a time in a..."

'Once upon a time in a world far far away'.truncate(27, 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)"
# File fastlane_core/lib/fastlane_core/string_filters.rb, line 20
def truncate(truncate_at, options = {})
  return dup unless length > truncate_at

  omission = options[:omission] || '...'
  length_with_room_for_omission = truncate_at - omission.length
  stop = \
    if options[:separator]
      rindex(options[: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) click to toggle source

Base taken from: www.ruby-forum.com/topic/57805

# 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