Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/file/bbfile.rb,
lib/time/bbtime.rb,
lib/string/roman.rb,
lib/string/bbstring.rb,
lib/string/matching.rb

Instance Method Summary collapse

Instance Method Details

#composition_similarity(str) ⇒ Object



100
101
102
# File 'lib/string/matching.rb', line 100

def composition_similarity str
  BBLib.composition_similarity self, str
end

#drop_symbolsObject



86
87
88
# File 'lib/string/bbstring.rb', line 86

def drop_symbols
  BBLib.drop_symbols self
end

#drop_symbols!Object



90
91
92
# File 'lib/string/bbstring.rb', line 90

def drop_symbols!
  replace BBLib.drop_symbols(self)
end

#encap_by?(str) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/string/bbstring.rb', line 115

def encap_by? str
  return self.start_with?(str) && self.end_with?(str)
end

#extract_floats(convert: true) ⇒ Object



98
99
100
# File 'lib/string/bbstring.rb', line 98

def extract_floats convert: true
  BBLib.extract_floats self, convert:convert
end

#extract_integers(convert: true) ⇒ Object



94
95
96
# File 'lib/string/bbstring.rb', line 94

def extract_integers convert: true
  BBLib.extract_integers self, convert:convert
end

#extract_numbers(convert: true) ⇒ Object



102
103
104
# File 'lib/string/bbstring.rb', line 102

def extract_numbers convert: true
  BBLib.extract_numbers self, convert:convert
end

#file_name(with_extension = true) ⇒ Object



72
73
74
# File 'lib/file/bbfile.rb', line 72

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_romanObject



56
57
58
# File 'lib/string/roman.rb', line 56

def from_roman
  BBLib.from_roman self
end

#from_roman!Object



60
61
62
# File 'lib/string/roman.rb', line 60

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



78
79
80
# File 'lib/string/bbstring.rb', line 78

def move_articles position = :front, capitalize = true
  BBLib.move_articles self, position, capitalize:capitalize
end

#move_articles!(position = :front, capitalize = true) ⇒ Object



82
83
84
# File 'lib/string/bbstring.rb', line 82

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.



68
69
70
71
72
73
74
75
76
# File 'lib/string/bbstring.rb', line 68

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) ⇒ Object



111
112
113
# File 'lib/time/bbtime.rb', line 111

def parse_duration output: :sec
  BBLib.parse_duration self, output:output
end

#parse_file_size(output: :byte) ⇒ Object



76
77
78
# File 'lib/file/bbfile.rb', line 76

def parse_file_size output: :byte
  BBLib.parse_file_size(self, output:output)
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

#to_aObject

Simple method to convert a string into an array containing only itself



111
112
113
# File 'lib/string/bbstring.rb', line 111

def to_a
  return [self]
end

#to_clean_symObject



106
107
108
# File 'lib/string/bbstring.rb', line 106

def to_clean_sym
  self.strip.downcase.gsub('_', ' ').drop_symbols.gsub(' ', '_').to_sym
end

#to_file(path, mkpath = true, mode: 'a') ⇒ Object



68
69
70
# File 'lib/file/bbfile.rb', line 68

def to_file path, mkpath = true, mode: 'a'
  BBLib.string_to_file path, self, mkpath, mode:mode
end

#to_romanObject



64
65
66
# File 'lib/string/roman.rb', line 64

def to_roman
  BBLib.string_to_roman self
end

#to_roman!Object



68
69
70
# File 'lib/string/roman.rb', line 68

def to_roman!
  replace self.to_roman
end