class String
Monkey patches for the String
class
Public Instance Methods
camel_case(style = :lower)
click to toggle source
# File lib/bblib/core/util/cases.rb, line 79 def camel_case(style = :lower) BBLib.camel_case self, style end
capital?()
click to toggle source
# File lib/bblib/core/util/string.rb, line 257 def capital? chars.first.upper? end
class_case()
click to toggle source
# File lib/bblib/core/util/cases.rb, line 95 def class_case BBLib.class_case(self) end
composition_similarity(str)
click to toggle source
# File lib/bblib/core/util/matching.rb, line 113 def composition_similarity(str) BBLib.composition_similarity self, str end
delimited_case(delimiter = '_')
click to toggle source
# File lib/bblib/core/util/cases.rb, line 83 def delimited_case(delimiter = '_') BBLib.delimited_case self, delimiter end
dirname()
click to toggle source
# File lib/bblib/core/util/file.rb, line 160 def dirname File.dirname(self) end
drop_symbols()
click to toggle source
# File lib/bblib/core/util/string.rb, line 162 def drop_symbols BBLib.drop_symbols self end
drop_symbols!()
click to toggle source
# File lib/bblib/core/util/string.rb, line 166 def drop_symbols! replace BBLib.drop_symbols(self) end
encap_by?(str)
click to toggle source
# File lib/bblib/core/util/string.rb, line 191 def encap_by?(str) case str when '(' start_with?(str) && end_with?(')') when '[' start_with?(str) && end_with?(']') when '{' start_with?(str) && end_with?('}') when '<' start_with?(str) && end_with?('>') else start_with?(str) && end_with?(str) end end
encap_split(expressions, *delimiters, **opts)
click to toggle source
Split on only delimiters not between specific encapsulators Various characters are special and automatically recognized such as parens which automatically match anything between a begin and end character.
Regex below is no longer used because of how inefficient it is. Comment is left in case it is ever useful again /(?<group>((?:*|g
# File lib/bblib/core/util/string.rb, line 148 def encap_split(expressions, *delimiters, **opts) BBLib::Splitter.split(self, *delimiters, **opts.merge(expressions: expressions)) end
Also aliased as: esplit
encapsulate(char = '"')
click to toggle source
# File lib/bblib/core/util/string.rb, line 206 def encapsulate(char = '"') back = case char when '(' ')' when '[' ']' when '{' '}' when '<' '>' else char end "#{char}#{self}#{back}" end
extract_floats(convert: true)
click to toggle source
# File lib/bblib/core/util/string.rb, line 174 def extract_floats(convert: true) BBLib.extract_floats self, convert: convert end
extract_integers(convert: true)
click to toggle source
# File lib/bblib/core/util/string.rb, line 170 def extract_integers(convert: true) BBLib.extract_integers self, convert: convert end
extract_numbers(convert: true)
click to toggle source
# File lib/bblib/core/util/string.rb, line 178 def extract_numbers(convert: true) BBLib.extract_numbers self, convert: convert end
file_name(with_extension = true)
click to toggle source
# File lib/bblib/core/util/file.rb, line 156 def file_name(with_extension = true) with_extension ? File.basename(self) : File.basename(self, File.extname(self)) end
from_roman()
click to toggle source
# File lib/bblib/core/util/roman.rb, line 50 def from_roman BBLib.from_roman self end
levenshtein_distance(str)
click to toggle source
# File lib/bblib/core/util/matching.rb, line 105 def levenshtein_distance(str) BBLib.levenshtein_distance self, str end
levenshtein_similarity(str)
click to toggle source
# File lib/bblib/core/util/matching.rb, line 109 def levenshtein_similarity(str) BBLib.levenshtein_similarity self, str end
lower?()
click to toggle source
# File lib/bblib/core/util/string.rb, line 253 def lower? chars.all? { |letter| /[[:lower:]]|\W/.match(letter) } end
method_case()
click to toggle source
# File lib/bblib/core/util/cases.rb, line 91 def method_case BBLib.method_case(self) end
move_articles(position = :front, capitalize = true)
click to toggle source
# File lib/bblib/core/util/string.rb, line 154 def move_articles(position = :front, capitalize = true) BBLib.move_articles self, position, capitalize: capitalize end
move_articles!(position = :front, capitalize = true)
click to toggle source
# File lib/bblib/core/util/string.rb, line 158 def move_articles!(position = :front, capitalize = true) replace BBLib.move_articles(self, position, capitalize: capitalize) end
msplit(*delims)
click to toggle source
Multi-split. Similar to split, but can be passed an array of delimiters to split on.
# File lib/bblib/core/util/string.rb, line 125 def msplit(*delims) ary = [self] return ary if delims.empty? delims.flatten.each do |d| ary = ary.flat_map { |a| a.split d } end ary end
numeric_similarity(str)
click to toggle source
# File lib/bblib/core/util/matching.rb, line 121 def numeric_similarity(str) BBLib.numeric_similarity self, str end
parse_duration(output: :sec, min_interval: :sec)
click to toggle source
# File lib/bblib/core/util/time.rb, line 165 def parse_duration(output: :sec, min_interval: :sec) BBLib.parse_duration self, output: output, min_interval: min_interval end
parse_file_size(*args)
click to toggle source
# File lib/bblib/core/util/file.rb, line 164 def parse_file_size(*args) BBLib.parse_file_size(self, *args) end
pathify()
click to toggle source
# File lib/bblib/core/util/file.rb, line 168 def pathify BBLib.pathify(self) end
phrase_similarity(str)
click to toggle source
# File lib/bblib/core/util/matching.rb, line 117 def phrase_similarity(str) BBLib.phrase_similarity self, str end
pluralize(num = 2)
click to toggle source
# File lib/bblib/core/util/pluralization.rb, line 139 def pluralize(num = 2) BBLib.pluralize(self, num) end
quote_split(*delimiters)
click to toggle source
Split on delimiters
# File lib/bblib/core/util/string.rb, line 135 def quote_split(*delimiters) encap_split(%w{" '}, *delimiters) end
Also aliased as: qsplit
qwerty_distance(str)
click to toggle source
# File lib/bblib/core/util/matching.rb, line 125 def qwerty_distance(str) BBLib.qwerty_distance self, str end
singularize()
click to toggle source
# File lib/bblib/core/util/pluralization.rb, line 143 def singularize BBLib.singularize(self) end
snake_case()
click to toggle source
# File lib/bblib/core/util/cases.rb, line 87 def snake_case BBLib.snake_case self end
spinal_case()
click to toggle source
# File lib/bblib/core/util/cases.rb, line 99 def spinal_case BBLib.spinal_case self end
start_case(first_only: false)
click to toggle source
# File lib/bblib/core/util/cases.rb, line 75 def start_case(first_only: false) BBLib.start_case self, first_only: first_only end
title_case(first_only: false)
click to toggle source
# File lib/bblib/core/util/cases.rb, line 71 def title_case(first_only: false) BBLib.title_case self, first_only: first_only end
to_a()
click to toggle source
Simple method to convert a string into an array containing only itself
# File lib/bblib/core/util/string.rb, line 187 def to_a [self] end
to_clean_sym()
click to toggle source
# File lib/bblib/core/util/string.rb, line 182 def to_clean_sym snake_case.to_sym end
to_color(color_code, opts = {})
click to toggle source
# File lib/bblib/cli/color.rb, line 48 def to_color(color_code, opts = {}) BBLib::Console.colorize(self, color_code, **opts) end
to_file(*args)
click to toggle source
# File lib/bblib/core/util/file.rb, line 152 def to_file(*args) BBLib.string_to_file(self, *args) end
to_regex(*options, ignore_invalid: false)
click to toggle source
# File lib/bblib/core/util/regexp.rb, line 42 def to_regex(*options, ignore_invalid: false) Regexp.from_s(self, *options, ignore_invalid: ignore_invalid) end
to_roman()
click to toggle source
# File lib/bblib/core/util/roman.rb, line 54 def to_roman BBLib.string_to_roman self end
train_case()
click to toggle source
# File lib/bblib/core/util/cases.rb, line 103 def train_case BBLib.train_case self end
uncapsulate(char = '"', limit: nil)
click to toggle source
# File lib/bblib/core/util/string.rb, line 222 def uncapsulate(char = '"', limit: nil) back = case char when '(' ')' when '[' ']' when '{' '}' when '<' '>' else char end temp = dup count = 0 while temp.start_with?(char) && temp != char && (limit.nil? || count < limit) temp = temp[(char.size)..-1] count += 1 end count = 0 while temp.end_with?(back) && temp != char && (limit.nil? || count < limit) temp = temp[0..-(char.size + 1)] count += 1 end temp end
upper?()
click to toggle source
# File lib/bblib/core/util/string.rb, line 249 def upper? chars.all? { |letter| /[[:upper:]]|\W/.match(letter) } end