Module: Ruuuby::Feature::Includable::StringF08
- Included in:
- String
- Defined in:
- lib/ruuuby/class/str/str.rb
Overview
defines the operations needed to support Feature(f08) that are applied to Class(String)
Instance Method Summary collapse
-
#downcase? ⇒ Boolean
True, if this
Stringis of length 1 and the character is lowercase. -
#ensure_ending!(ending) ⇒ String
The original string with ending-string added if missing prior.
-
#ensure_start!(start) ⇒ String
The original string with the starting text added if at least partially missing prior.
-
#remove_until(stop_at, num_matches = 1) ⇒ String
Self, with all content (leading up to argterminating_pattern) removed.
-
#remove_until_last(stop_at) ⇒ String
Self, with all content (leading up to argterminating_pattern) removed.
-
#upcase? ⇒ Boolean
True, if this
Stringis of length 1 and the character is uppercase. -
#♻️⟵(stop_at, num_matches = 1) ⇒ String
Self, with all content (leading up to argstop_at) removed, searched from reversed order and then returned back in original order.
Instance Method Details
#downcase? ⇒ Boolean
Returns true, if this String is of length 1 and the character is lowercase.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruuuby/class/str/str.rb', line 30 def downcase? case(self.𝔠) when 1 return self.₀.match?(::String.syntax_char_lowercase) when 0 return false else return self.🐍? end end |
#ensure_ending!(ending) ⇒ String
Returns the original string with ending-string added if missing prior.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ruuuby/class/str/str.rb', line 117 def ensure_ending!(ending) 🛑str❓(:ending, ending) return self if ending.∅? || self.end_with?(ending) return self << ending if self.∅? last_matched = '' delta = 0 while delta <= self.𝔠 && delta <= ending.𝔠 starting_of_end = ending[0..delta] last_matched = starting_of_end if self[(self.𝔠-1-delta)..(self.𝔠-1)] == starting_of_end delta += 1 end self << (last_matched.∅? ? ending : ending[last_matched.𝔠..ending.𝔠-1]) end |
#ensure_start!(start) ⇒ String
Returns the original string with the starting text added if at least partially missing prior.
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ruuuby/class/str/str.rb', line 98 def ensure_start!(start) 🛑str❓(:start, start) return self if start.∅? || self.start_with?(start) return self >> start if self.∅? last_matched = '' delta = 0 while delta <= self.𝔠 && delta <= start.𝔠 ending_of_start = start[(start.𝔠-1-delta)..(start.𝔠-1)] last_matched = ending_of_start if self[0..delta] == ending_of_start delta += 1 end self >> (last_matched.∅? ? start : start[0..(start.𝔠-1-last_matched.𝔠)]) end |
#remove_until(stop_at, num_matches = 1) ⇒ String
Returns self, with all content (leading up to argterminating_pattern) removed.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruuuby/class/str/str.rb', line 47 def remove_until(stop_at, num_matches=1) 🛑str❓(:stop_at, stop_at, :∉∅) 🛑int❓(:num_matches, num_matches) return '' if self == stop_at 🛑 RuntimeError.🆕("| c{String}-> m{remove_until} got arg(stop_at){#{stop_at}} which is not contained in self{#{self}} |") if (self.∅? || self.∌?(stop_at)) 🛑 ArgumentError.🆕("| c{String}-> m{remove_until} got arg(stop_at){#{stop_at}}-len{#{stop_at.𝔠.to_s}} which is longer than self{#{self}} of len{#{self.𝔠.to_s}} |") if stop_at.𝔠 > self.𝔠 if num_matches == -1 || num_matches == ::Float::INFINITY return self[(self.rindex(stop_at)+stop_at.𝔠)..self.𝔠₋] elsif num_matches == 1 return self[(self.index(stop_at)+stop_at.𝔠)..self.𝔠₋] else num_matched = 0 position = 0 len_pattern = stop_at.length while position <= (self.length - len_pattern) curr = self[position...(position+len_pattern)] if curr == stop_at num_matched += 1 if num_matched >= num_matches return self[(position+len_pattern)...self.length] end end position += 1 end 🛑 ArgumentError.🆕("| c{String}-> c{remove_until} got arg(num_matches) and self{#{self}} does not have{#{num_matches.to_s}} instances of{#{stop_at}} |") end end |
#remove_until_last(stop_at) ⇒ String
Returns self, with all content (leading up to argterminating_pattern) removed.
91 |
# File 'lib/ruuuby/class/str/str.rb', line 91 def remove_until_last(stop_at) ; self.remove_until(stop_at, -1) ; end |
#upcase? ⇒ Boolean
Returns true, if this String is of length 1 and the character is uppercase.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruuuby/class/str/str.rb', line 18 def upcase? case(self.𝔠) when 1 return self.₀.match?(::String.syntax_char_uppercase) when 0 return false else return self.🐫? || 🐍⬆? end end |
#♻️⟵(stop_at, num_matches = 1) ⇒ String
Returns self, with all content (leading up to argstop_at) removed, searched from reversed order and then returned back in original order.
81 82 83 84 |
# File 'lib/ruuuby/class/str/str.rb', line 81 def ♻️⟵(stop_at, num_matches=1) 🛑str❓(:stop_at, stop_at, :∉∅) self.↩.♻️⟶(stop_at.reverse, num_matches).↩ end |