Class: AttributedString
- Inherits:
-
String
- Object
- String
- AttributedString
- Defined in:
- lib/attributed_string/klass.rb,
lib/attributed_string/refine.rb,
lib/attributed_string/inspect.rb,
lib/attributed_string/version.rb,
lib/attributed_string/attachment.rb,
lib/attributed_string/string_ops.rb,
lib/attributed_string/unsupported.rb,
lib/attributed_string/filter_result.rb,
lib/attributed_string/needs_testing.rb
Defined Under Namespace
Modules: Refinements Classes: FilterResult, Todo
Constant Summary collapse
- VERSION =
"0.1.0"- ATTACHMENT_CHARACTER =
This character Object Replacement Character is used to represent an attachment in the string.
"\u{FFFC}".freeze
Instance Method Summary collapse
-
#%(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#*(*args, **kwargs, &block) ⇒ Object
Unsupported.
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #[]=(arg, *args, value) ⇒ Object
-
#add_arr_attrs(range = 0..self.length - 1, **attributes) ⇒ AttributedString
Adds the given attributes in the hash to the range.
-
#add_attachment(attachment, position: self.length) ⇒ AttributedString
Adds an attachment to the given position.
-
#add_attrs(range = 0..self.length - 1, **attributes) ⇒ AttributedString
Adds the given attributes in the hash to the range.
-
#attachment_at(position) ⇒ Object
Returns the attachments at a specific position.
-
#attachments(range: 0...self.length) ⇒ Array<Object>
Returns an array of attachments in the given range.
-
#attachments_with_positions(range: 0...self.length) ⇒ Object
TODO: needs a test.
-
#attrs_at(position) ⇒ Hash
Returns the attributes at a specific position.
-
#b(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#byteslice(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#center(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#chomp(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#chomp!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#chop(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#chop!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#chr(*args, **kwargs, &block) ⇒ Object
Unsupported.
- #clear ⇒ Object
-
#concat(other) ⇒ Object
(also: #<<)
TODO: this should take args not other can be implemented as (other, *args).
-
#delete(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#delete!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#delete_attachment(position) ⇒ Object
Deletes the attachment at a specific position.
-
#delete_prefix(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#delete_prefix!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#delete_suffix(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#delete_suffix!(*args, **kwargs, &block) ⇒ Object
Unsupported.
- #dim(string, color: true) ⇒ Object
-
#dump(*args, **kwargs, &block) ⇒ Object
Unsupported.
- #dup ⇒ Object
-
#encode(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#filter(&block) ⇒ AttributedString::FilterResult
Returns a filtered string the block will be called with each attribute, value pair.
-
#gsub(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#gsub!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#has_attachment?(range: 0...self.length) ⇒ Boolean
Check if the string has an attachment.
-
#initialize(string = "", **attrs) ⇒ AttributedString
constructor
Returns a new instance of AttributedString with the kwargs passed in as attributes for the whole string.
- #insert(index, other) ⇒ Object
-
#inspect(color: false) ⇒ Object
“and these have none”).inspect.
-
#lines(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#ljust(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#lstrip(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#lstrip!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#partition(*args, **kwargs, &block) ⇒ Object
Unsupported.
- #prepend(other) ⇒ Object
-
#remove_attrs(range_or_key, *attribute_keys) ⇒ AttributedString
Removes the given attributes from a range.
-
#replace(other) ⇒ Object
modifies the string or returns a modified string.
-
#reverse(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#reverse!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#rjust(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#rpartition(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#rstrip(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#rstrip!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#scan(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#scrub(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#setbyte(*args, **kwargs, &block) ⇒ Object
Unsupported.
- #slice(arg, *args) ⇒ Object (also: #[])
- #slice!(arg, *args) ⇒ Object
-
#split(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#squeeze(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#squeeze!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#strip(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#strip!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#sub(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#sub!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#succ(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#succ!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#tr(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#tr!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#tr_s(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#tr_s!(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#undump(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#unicode_normalize(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#unpack(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#unpack1(*args, **kwargs, &block) ⇒ Object
Unsupported.
-
#upto(*args, **kwargs, &block) ⇒ Object
Unsupported.
Constructor Details
#initialize(string = "", **attrs) ⇒ AttributedString
Returns a new instance of AttributedString with the kwargs passed in as attributes for the whole string.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/attributed_string/klass.rb', line 9 def initialize(string = "", **attrs) super(string) @store = [] if string.is_a?(AttributedString) string.instance_variable_get(:@store).each do |entry| @store << entry.dup end end add_attrs(**attrs) end |
Instance Method Details
#%(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
148 |
# File 'lib/attributed_string/unsupported.rb', line 148 def %(*args, **kwargs, &block) = raise Todo |
#*(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
186 |
# File 'lib/attributed_string/unsupported.rb', line 186 def *(*args, **kwargs, &block) = raise Todo |
#+(other) ⇒ Object
79 80 81 |
# File 'lib/attributed_string/string_ops.rb', line 79 def +(other) self.dup.concat(other) end |
#==(other) ⇒ Object
104 105 106 107 108 |
# File 'lib/attributed_string/klass.rb', line 104 def ==(other) return false unless other.is_a?(AttributedString) # not super efficient, but it works for now (0...length).all? { |i| attrs_at(i) == other.attrs_at(i) && (i) == other.(i) } && super end |
#[]=(arg, *args, value) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/attributed_string/string_ops.rb', line 83 def []=(arg, *args, value) if arg.is_a?(Regexp) raise Todo, "Regular expression assignment not implemented for []=, consider raising a pull request" end value ||= "" value = value.is_a?(AttributedString) ? value : self.class.new(value) range = arg.is_a?(Range) ? normalize_range(arg) : normalize_integer_slice_args(arg, *args) return nil if range.nil? slice!(range) insert(range.begin, value) value end |
#add_arr_attrs(range = 0..self.length - 1, **attributes) ⇒ AttributedString
Adds the given attributes in the hash to the range.
If the attribute is already set, it will be converted to an array and the new value will be appended.
48 49 50 51 52 53 |
# File 'lib/attributed_string/klass.rb', line 48 def add_arr_attrs(range = 0..self.length - 1, **attributes) range = normalize_range(range) return self if attributes.empty? || self.empty? || range.nil? || range.size.zero? @store << { range: range, arr_attributes: attributes } self end |
#add_attachment(attachment, position: self.length) ⇒ AttributedString
Adds an attachment to the given position.
9 10 11 12 13 14 15 16 |
# File 'lib/attributed_string/attachment.rb', line 9 def (, position: self.length) self.insert(position, ATTACHMENT_CHARACTER) range = normalize_range(position..position) raise ArgumentError, "Position out of bounds" if range.nil? @store << { range:, attachment: } self end |
#add_attrs(range = 0..self.length - 1, **attributes) ⇒ AttributedString
Adds the given attributes in the hash to the range.
34 35 36 37 38 39 |
# File 'lib/attributed_string/klass.rb', line 34 def add_attrs(range = 0..self.length - 1, **attributes) range = normalize_range(range) return self if attributes.empty? || self.empty? || range.nil? || range.size.zero? @store << { range: range, attributes: attributes } self end |
#attachment_at(position) ⇒ Object
Returns the attachments at a specific position.
39 40 41 42 43 44 45 46 47 |
# File 'lib/attributed_string/attachment.rb', line 39 def (position) result = nil @store.each do |stored_val| if stored_val[:range].begin == position && stored_val[:attachment] result = stored_val[:attachment] end end result end |
#attachments(range: 0...self.length) ⇒ Array<Object>
Returns an array of attachments in the given range.
52 53 54 |
# File 'lib/attributed_string/attachment.rb', line 52 def (range: 0...self.length) (range: range).map { || [:attachment] } end |
#attachments_with_positions(range: 0...self.length) ⇒ Object
TODO: needs a test
57 58 59 60 61 62 63 64 65 |
# File 'lib/attributed_string/attachment.rb', line 57 def (range: 0...self.length) range = normalize_range(range) return [] if range.nil? = [] self.chars[range].map.with_index do |char, i| << { attachment: (range.begin + i), position: range.begin + i } if char == ATTACHMENT_CHARACTER end end |
#attrs_at(position) ⇒ Hash
Returns the attributes at a specific position.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/attributed_string/klass.rb', line 79 def attrs_at(position) result = {} @store.each do |stored_val| if stored_val[:range].include?(position) if stored_val[:delete] stored_val[:delete].each do |key| result.delete(key) end elsif stored_val[:arr_attributes] stored_val[:arr_attributes].each do |key, value| result[key] = [result[key]] if result.key?(key) && !result[key].is_a?(Array) if value.is_a?(Array) (result[key] ||= []).concat(value) else (result[key] ||= []).push(value) end end elsif stored_val[:attributes] result.merge!(stored_val[:attributes]) end end end result end |
#b(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
122 |
# File 'lib/attributed_string/unsupported.rb', line 122 def b(*args, **kwargs, &block) = raise Todo |
#byteslice(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
178 |
# File 'lib/attributed_string/unsupported.rb', line 178 def byteslice(*args, **kwargs, &block) = raise Todo |
#center(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
110 |
# File 'lib/attributed_string/unsupported.rb', line 110 def center(*args, **kwargs, &block) = raise Todo |
#chomp(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
92 |
# File 'lib/attributed_string/unsupported.rb', line 92 def chomp(*args, **kwargs, &block) = raise Todo |
#chomp!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
96 |
# File 'lib/attributed_string/unsupported.rb', line 96 def chomp!(*args, **kwargs, &block) = raise Todo |
#chop(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
100 |
# File 'lib/attributed_string/unsupported.rb', line 100 def chop(*args, **kwargs, &block) = raise Todo |
#chop!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
104 |
# File 'lib/attributed_string/unsupported.rb', line 104 def chop!(*args, **kwargs, &block) = raise Todo |
#chr(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
182 |
# File 'lib/attributed_string/unsupported.rb', line 182 def chr(*args, **kwargs, &block) = raise Todo |
#clear ⇒ Object
3 4 5 6 |
# File 'lib/attributed_string/needs_testing.rb', line 3 def clear @store.clear super end |
#concat(other) ⇒ Object Also known as: <<
TODO: this should take args not other can be implemented as (other, *args)
52 53 54 55 56 57 58 59 |
# File 'lib/attributed_string/string_ops.rb', line 52 def concat(other) if other.is_a?(AttributedString) store = other.instance_variable_get(:@store).map { |obj| obj.dup } translate_ranges(store, distance: self.length) @store.concat(store) end super end |
#delete(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
154 |
# File 'lib/attributed_string/unsupported.rb', line 154 def delete(*args, **kwargs, &block) = raise Todo |
#delete!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
158 |
# File 'lib/attributed_string/unsupported.rb', line 158 def delete!(*args, **kwargs, &block) = raise Todo |
#delete_attachment(position) ⇒ Object
Deletes the attachment at a specific position.
21 22 23 24 25 |
# File 'lib/attributed_string/attachment.rb', line 21 def (position) = (position) self[position] = '' end |
#delete_prefix(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
162 |
# File 'lib/attributed_string/unsupported.rb', line 162 def delete_prefix(*args, **kwargs, &block) = raise Todo |
#delete_prefix!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
166 |
# File 'lib/attributed_string/unsupported.rb', line 166 def delete_prefix!(*args, **kwargs, &block) = raise Todo |
#delete_suffix(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
170 |
# File 'lib/attributed_string/unsupported.rb', line 170 def delete_suffix(*args, **kwargs, &block) = raise Todo |
#delete_suffix!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
174 |
# File 'lib/attributed_string/unsupported.rb', line 174 def delete_suffix!(*args, **kwargs, &block) = raise Todo |
#dim(string, color: true) ⇒ Object
91 92 93 |
# File 'lib/attributed_string/inspect.rb', line 91 def dim(string, color: true) color ? "\e[2m#{string}\e[22m" : string end |
#dump(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
140 |
# File 'lib/attributed_string/unsupported.rb', line 140 def dump(*args, **kwargs, &block) = raise Todo |
#dup ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/attributed_string/klass.rb', line 20 def dup super.tap do |copy| new_store = @store.map do |entry| entry[:range] = entry[:range].dup entry.dup end copy.instance_variable_set(:@store, new_store) end end |
#encode(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
134 |
# File 'lib/attributed_string/unsupported.rb', line 134 def encode(*args, **kwargs, &block) = raise Todo |
#filter(&block) ⇒ AttributedString::FilterResult
Returns a filtered string the block will be called with each attribute, value pair. It’s an inclusive filter, so if the block returns true, any character with that attribute will be included.
This method has been slightly optimized to minimize allocations.
12 13 14 |
# File 'lib/attributed_string/filter_result.rb', line 12 def filter(&block) AttributedString::FilterResult.new(self, &block) end |
#gsub(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
8 |
# File 'lib/attributed_string/unsupported.rb', line 8 def gsub(*args, **kwargs, &block) = raise Todo |
#gsub!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
12 |
# File 'lib/attributed_string/unsupported.rb', line 12 def gsub!(*args, **kwargs, &block) = raise Todo |
#has_attachment?(range: 0...self.length) ⇒ Boolean
Check if the string has an attachment
30 31 32 33 34 |
# File 'lib/attributed_string/attachment.rb', line 30 def (range: 0...self.length) range = normalize_range(range) return false if range.nil? (self.to_s[range]||'').include?(ATTACHMENT_CHARACTER) end |
#insert(index, other) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/attributed_string/string_ops.rb', line 3 def insert(index, other) return super if other.empty? other = AttributedString.new(other) unless other.is_a?(AttributedString) index = normalize_index(index, len: self.length + 1) split_ranges(@store, index, other.length, self.length + other.length) store = other.instance_variable_get(:@store).map { |obj| obj.dup } translate_ranges(store, distance: index) @store.concat(store) super end |
#inspect(color: false) ⇒ Object
“and these have none”).inspect
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/attributed_string/inspect.rb', line 11 def inspect(color: false) # Collect all positions where attributes change positions = Set.new @store.each do |attr| range = attr[:range] positions << range.begin positions << range.begin + range.size end # Include the start and end positions of the string positions << 0 positions << self.length # Sort all positions positions = positions.to_a.sort result = "" last_attrs = {} # Initialize as empty hash positions.each_cons(2) do |start_pos, end_pos| next if start_pos >= end_pos # Skip invalid ranges substring = self.to_s[start_pos...end_pos] attrs_before = last_attrs = (start_pos) attrs_after = attrs_at(start_pos) # Determine attribute changes ended_attrs = {} started_attrs = {} # Attributes that have ended or changed attrs_before.each do |key, value| if !attrs_after.key?(key) # Attribute has ended ended_attrs[key] = value elsif attrs_after[key] != value # Attribute value has changed; treat as ending old and starting new ended_attrs[key] = value started_attrs[key] = attrs_after[key] end end # Attributes that have started attrs_after.each do |key, value| if !attrs_before.key?(key) started_attrs[key] = value end end # Remove attributes that both ended and started (value change) ended_attrs.delete_if { |k, _| started_attrs.key?(k) } unless ended_attrs.empty? && started_attrs.empty? attrs_str = ended_attrs.keys.sort.map{ |k| "-#{k}" } attrs_str += started_attrs.to_a.sort{ |a,b| a[0] <=> b[0] }.map{ |a| "#{a[0]}: #{a[1]}" } attrs_str = "{ #{attrs_str.join(', ')} }" result += dim(attrs_str, color: color) end if substring = dim("[#{}]", color: color) end # Append the substring result += substring last_attrs = attrs_after end # Close any remaining attributes unless last_attrs.empty? result += dim("{ #{last_attrs.keys.sort.map{ |k| "-#{k}" }.join(", ")} }", color: color) end result end |
#lines(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
191 |
# File 'lib/attributed_string/unsupported.rb', line 191 def lines(*args, **kwargs, &block) = raise Todo |
#ljust(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
114 |
# File 'lib/attributed_string/unsupported.rb', line 114 def ljust(*args, **kwargs, &block) = raise Todo |
#lstrip(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
68 |
# File 'lib/attributed_string/unsupported.rb', line 68 def lstrip(*args, **kwargs, &block) = raise Todo |
#lstrip!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
72 |
# File 'lib/attributed_string/unsupported.rb', line 72 def lstrip!(*args, **kwargs, &block) = raise Todo |
#partition(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
195 |
# File 'lib/attributed_string/unsupported.rb', line 195 def partition(*args, **kwargs, &block) = raise Todo |
#prepend(other) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/attributed_string/string_ops.rb', line 62 def prepend(other) if other.is_a?(AttributedString) store = other.instance_variable_get(:@store).map { |obj| obj.dup } translate_ranges(@store, distance: other.length) @store.concat(store) end super end |
#remove_attrs(range_or_key, *attribute_keys) ⇒ AttributedString
Removes the given attributes from a range.
67 68 69 70 71 72 73 74 |
# File 'lib/attributed_string/klass.rb', line 67 def remove_attrs(range_or_key, *attribute_keys) if !range_or_key.is_a?(Range) attribute_keys << range_or_key range_or_key = 0..self.length - 1 end @store << { range: range_or_key, delete: attribute_keys } self end |
#replace(other) ⇒ Object
modifies the string or returns a modified string
73 74 75 76 77 |
# File 'lib/attributed_string/string_ops.rb', line 73 def replace(other) super other_store = other.instance_variable_get(:@store) || [] @store = other_store.map { |obj| obj.dup } end |
#reverse(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
32 |
# File 'lib/attributed_string/unsupported.rb', line 32 def reverse(*args, **kwargs, &block) = raise Todo |
#reverse!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
36 |
# File 'lib/attributed_string/unsupported.rb', line 36 def reverse!(*args, **kwargs, &block) = raise Todo |
#rjust(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
118 |
# File 'lib/attributed_string/unsupported.rb', line 118 def rjust(*args, **kwargs, &block) = raise Todo |
#rpartition(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
199 |
# File 'lib/attributed_string/unsupported.rb', line 199 def rpartition(*args, **kwargs, &block) = raise Todo |
#rstrip(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
76 |
# File 'lib/attributed_string/unsupported.rb', line 76 def rstrip(*args, **kwargs, &block) = raise Todo |
#rstrip!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
80 |
# File 'lib/attributed_string/unsupported.rb', line 80 def rstrip!(*args, **kwargs, &block) = raise Todo |
#scan(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
207 |
# File 'lib/attributed_string/unsupported.rb', line 207 def scan(*args, **kwargs, &block) = raise Todo |
#scrub(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
126 |
# File 'lib/attributed_string/unsupported.rb', line 126 def scrub(*args, **kwargs, &block) = raise Todo |
#setbyte(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
40 |
# File 'lib/attributed_string/unsupported.rb', line 40 def setbyte(*args, **kwargs, &block) = raise Todo |
#slice(arg, *args) ⇒ Object Also known as: []
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/attributed_string/string_ops.rb', line 14 def slice(arg, *args) result = super raise Todo, "Regular expression not implemented for slice, consider raising a pull request" if arg.is_a?(Regexp) range = arg.is_a?(Range) ? normalize_range(arg) : normalize_integer_slice_args(arg, *args) return range if range.nil? raise RuntimeError if range.size != result.length store = @store.map do |obj| clamped = clamp_range(obj[:range], range) next nil if clamped.nil? obj.dup.tap do |obj| obj[:range] = translate_range(clamped, distance: -range.begin) end end.compact new_string = self.class.new(result) new_string.instance_variable_set(:@store, store) new_string end |
#slice!(arg, *args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/attributed_string/string_ops.rb', line 36 def slice!(arg, *args) result = slice(arg, *args) return result if result.nil? range = arg.is_a?(Range) ? normalize_range(arg) : normalize_integer_slice_args(arg, *args) return result if range.nil? super(range) split_ranges(@store, range.begin, -range.size, self.length) result end |
#split(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
203 |
# File 'lib/attributed_string/unsupported.rb', line 203 def split(*args, **kwargs, &block) = raise Todo |
#squeeze(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
60 |
# File 'lib/attributed_string/unsupported.rb', line 60 def squeeze(*args, **kwargs, &block) = raise Todo |
#squeeze!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
64 |
# File 'lib/attributed_string/unsupported.rb', line 64 def squeeze!(*args, **kwargs, &block) = raise Todo |
#strip(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
84 |
# File 'lib/attributed_string/unsupported.rb', line 84 def strip(*args, **kwargs, &block) = raise Todo |
#strip!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
88 |
# File 'lib/attributed_string/unsupported.rb', line 88 def strip!(*args, **kwargs, &block) = raise Todo |
#sub(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
16 |
# File 'lib/attributed_string/unsupported.rb', line 16 def sub(*args, **kwargs, &block) = raise Todo |
#sub!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
20 |
# File 'lib/attributed_string/unsupported.rb', line 20 def sub!(*args, **kwargs, &block) = raise Todo |
#succ(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
24 |
# File 'lib/attributed_string/unsupported.rb', line 24 def succ(*args, **kwargs, &block) = raise Todo |
#succ!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
28 |
# File 'lib/attributed_string/unsupported.rb', line 28 def succ!(*args, **kwargs, &block) = raise Todo |
#tr(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
44 |
# File 'lib/attributed_string/unsupported.rb', line 44 def tr(*args, **kwargs, &block) = raise Todo |
#tr!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
48 |
# File 'lib/attributed_string/unsupported.rb', line 48 def tr!(*args, **kwargs, &block) = raise Todo |
#tr_s(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
52 |
# File 'lib/attributed_string/unsupported.rb', line 52 def tr_s(*args, **kwargs, &block) = raise Todo |
#tr_s!(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
56 |
# File 'lib/attributed_string/unsupported.rb', line 56 def tr_s!(*args, **kwargs, &block) = raise Todo |
#undump(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
144 |
# File 'lib/attributed_string/unsupported.rb', line 144 def undump(*args, **kwargs, &block) = raise Todo |
#unicode_normalize(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
130 |
# File 'lib/attributed_string/unsupported.rb', line 130 def unicode_normalize(*args, **kwargs, &block) = raise Todo |
#unpack(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
211 |
# File 'lib/attributed_string/unsupported.rb', line 211 def unpack(*args, **kwargs, &block) = raise Todo |
#unpack1(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
215 |
# File 'lib/attributed_string/unsupported.rb', line 215 def unpack1(*args, **kwargs, &block) = raise Todo |
#upto(*args, **kwargs, &block) ⇒ Object
Unsupported. Consider opening pull request
219 |
# File 'lib/attributed_string/unsupported.rb', line 219 def upto(*args, **kwargs, &block) = raise Todo |