Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/file/bbfile.rb,
lib/time/bbtime.rb,
lib/string/cases.rb,
lib/string/roman.rb,
lib/string/bbstring.rb,
lib/string/matching.rb
Instance Method Summary collapse
- #camel_case(style = :lower) ⇒ Object
- #composition_similarity(str) ⇒ Object
- #delimited_case(delimiter = '_') ⇒ Object
- #dirname ⇒ Object
- #drop_symbols ⇒ Object
- #drop_symbols! ⇒ Object
- #encap_by?(str) ⇒ Boolean
- #extract_floats(convert: true) ⇒ Object
- #extract_integers(convert: true) ⇒ Object
- #extract_numbers(convert: true) ⇒ Object
- #file_name(with_extension = true) ⇒ Object
- #from_roman ⇒ Object
- #from_roman! ⇒ Object
- #levenshtein_distance(str) ⇒ Object
- #levenshtein_similarity(str) ⇒ Object
- #move_articles(position = :front, capitalize = true) ⇒ Object
- #move_articles!(position = :front, capitalize = true) ⇒ Object
-
#msplit(*delims, keep_empty: false) ⇒ Object
Multi-split.
- #numeric_similarity(str) ⇒ Object
- #parse_duration(output: :sec, min_interval: :sec) ⇒ Object
- #parse_file_size(output: :byte) ⇒ Object
- #pathify ⇒ Object
- #phrase_similarity(str) ⇒ Object
- #qwerty_distance(str) ⇒ Object
- #snake_case ⇒ Object
- #spinal_case ⇒ Object
- #start_case(first_only: false) ⇒ Object
- #title_case(first_only: false) ⇒ Object
-
#to_a ⇒ Object
Simple method to convert a string into an array containing only itself.
- #to_clean_sym ⇒ Object
- #to_file(path, mkpath = true, mode: 'a') ⇒ Object
- #to_roman ⇒ Object
- #to_roman! ⇒ Object
- #train_case ⇒ Object
- #uncapsulate(char = '"') ⇒ Object
Instance Method Details
#camel_case(style = :lower) ⇒ Object
76 77 78 |
# File 'lib/string/cases.rb', line 76 def camel_case style = :lower BBLib.camel_case self, style end |
#composition_similarity(str) ⇒ Object
100 101 102 |
# File 'lib/string/matching.rb', line 100 def composition_similarity str BBLib.composition_similarity self, str end |
#delimited_case(delimiter = '_') ⇒ Object
80 81 82 |
# File 'lib/string/cases.rb', line 80 def delimited_case delimiter = '_' BBLib.delimited_case self, delimiter end |
#dirname ⇒ Object
83 84 85 |
# File 'lib/file/bbfile.rb', line 83 def dirname self.scan(/.*(?=\/)/).first end |
#drop_symbols ⇒ Object
83 84 85 |
# File 'lib/string/bbstring.rb', line 83 def drop_symbols BBLib.drop_symbols self end |
#drop_symbols! ⇒ Object
87 88 89 |
# File 'lib/string/bbstring.rb', line 87 def drop_symbols! replace BBLib.drop_symbols(self) end |
#encap_by?(str) ⇒ Boolean
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/string/bbstring.rb', line 112 def encap_by? str case str when '(' self.start_with?(str) && self.end_with?(')') when '[' self.start_with?(str) && self.end_with?(']') when '{' self.start_with?(str) && self.end_with?('}') when '<' self.start_with?(str) && self.end_with?('>') else self.start_with?(str) && self.end_with?(str) end end |
#extract_floats(convert: true) ⇒ Object
95 96 97 |
# File 'lib/string/bbstring.rb', line 95 def extract_floats convert: true BBLib.extract_floats self, convert:convert end |
#extract_integers(convert: true) ⇒ Object
91 92 93 |
# File 'lib/string/bbstring.rb', line 91 def extract_integers convert: true BBLib.extract_integers self, convert:convert end |
#extract_numbers(convert: true) ⇒ Object
99 100 101 |
# File 'lib/string/bbstring.rb', line 99 def extract_numbers convert: true BBLib.extract_numbers self, convert:convert end |
#file_name(with_extension = true) ⇒ Object
79 80 81 |
# File 'lib/file/bbfile.rb', line 79 def file_name with_extension = true self[(self.include?('/') ? self.rindex('/').to_i+1 : 0)..(with_extension ? -1 : self.rindex('.').to_i-1)] end |
#from_roman ⇒ Object
55 56 57 |
# File 'lib/string/roman.rb', line 55 def from_roman BBLib.from_roman self end |
#from_roman! ⇒ Object
59 60 61 |
# File 'lib/string/roman.rb', line 59 def from_roman! replace self.from_roman end |
#levenshtein_distance(str) ⇒ Object
92 93 94 |
# File 'lib/string/matching.rb', line 92 def levenshtein_distance str BBLib.levenshtein_distance self, str end |
#levenshtein_similarity(str) ⇒ Object
96 97 98 |
# File 'lib/string/matching.rb', line 96 def levenshtein_similarity str BBLib.levenshtein_similarity self, str end |
#move_articles(position = :front, capitalize = true) ⇒ Object
75 76 77 |
# File 'lib/string/bbstring.rb', line 75 def move_articles position = :front, capitalize = true BBLib.move_articles self, position, capitalize:capitalize end |
#move_articles!(position = :front, capitalize = true) ⇒ Object
79 80 81 |
# File 'lib/string/bbstring.rb', line 79 def move_articles! position = :front, capitalize = true replace BBLib.move_articles(self, position, capitalize:capitalize) end |
#msplit(*delims, keep_empty: false) ⇒ Object
Multi-split. Similar to split, but can be passed an array of delimiters to split on.
65 66 67 68 69 70 71 72 73 |
# File 'lib/string/bbstring.rb', line 65 def msplit *delims, keep_empty: false return [self] unless !delims.nil? && !delims.empty? ar = [self] [delims].flatten.each do |d| ar.map!{ |a| a.split d } ar.flatten! end keep_empty ? ar : ar.reject{ |l| l.empty? } end |
#numeric_similarity(str) ⇒ Object
108 109 110 |
# File 'lib/string/matching.rb', line 108 def numeric_similarity str BBLib.numeric_similarity self, str end |
#parse_duration(output: :sec, min_interval: :sec) ⇒ Object
127 128 129 |
# File 'lib/time/bbtime.rb', line 127 def parse_duration output: :sec, min_interval: :sec BBLib.parse_duration self, output:output, min_interval:min_interval end |
#parse_file_size(output: :byte) ⇒ Object
87 88 89 |
# File 'lib/file/bbfile.rb', line 87 def parse_file_size output: :byte BBLib.parse_file_size(self, output:output) end |
#pathify ⇒ Object
91 92 93 |
# File 'lib/file/bbfile.rb', line 91 def pathify BBLib.pathify(self) end |
#phrase_similarity(str) ⇒ Object
104 105 106 |
# File 'lib/string/matching.rb', line 104 def phrase_similarity str BBLib.phrase_similarity self, str end |
#qwerty_distance(str) ⇒ Object
112 113 114 |
# File 'lib/string/matching.rb', line 112 def qwerty_distance str BBLib.qwerty_distance self, str end |
#snake_case ⇒ Object
84 85 86 |
# File 'lib/string/cases.rb', line 84 def snake_case BBLib.snake_case self end |
#spinal_case ⇒ Object
88 89 90 |
# File 'lib/string/cases.rb', line 88 def spinal_case BBLib.spinal_case self end |
#start_case(first_only: false) ⇒ Object
72 73 74 |
# File 'lib/string/cases.rb', line 72 def start_case first_only: false BBLib.start_case self, first_only:first_only end |
#title_case(first_only: false) ⇒ Object
68 69 70 |
# File 'lib/string/cases.rb', line 68 def title_case first_only: false BBLib.title_case self, first_only:first_only end |
#to_a ⇒ Object
Simple method to convert a string into an array containing only itself
108 109 110 |
# File 'lib/string/bbstring.rb', line 108 def to_a [self] end |
#to_clean_sym ⇒ Object
103 104 105 |
# File 'lib/string/bbstring.rb', line 103 def to_clean_sym self.snake_case.to_sym end |
#to_file(path, mkpath = true, mode: 'a') ⇒ Object
75 76 77 |
# File 'lib/file/bbfile.rb', line 75 def to_file path, mkpath = true, mode: 'a' BBLib.string_to_file path, self, mkpath, mode:mode end |
#to_roman ⇒ Object
63 64 65 |
# File 'lib/string/roman.rb', line 63 def to_roman BBLib.string_to_roman self end |
#to_roman! ⇒ Object
67 68 69 |
# File 'lib/string/roman.rb', line 67 def to_roman! replace self.to_roman end |
#train_case ⇒ Object
92 93 94 |
# File 'lib/string/cases.rb', line 92 def train_case BBLib.train_case self end |
#uncapsulate(char = '"') ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/string/bbstring.rb', line 127 def uncapsulate char = '"' case char when '(' back = ')' when '[' back = ']' when '{' back = '}' when '<' back = '>' else back = char end temp = self.dup temp = temp[(char.size)..-1] while temp.start_with?(char) && temp != char temp = temp[0..-(char.size + 1)] while temp.end_with?(back) && temp != char temp end |