Module: CharacterSet::RubyFallback::CharacterSetMethods
- Included in:
- CharacterSet::RubyFallback
- Defined in:
- lib/character_set/ruby_fallback/character_set_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #case_insensitive ⇒ Object
- #cover?(string) ⇒ Boolean
- #delete_in(string) ⇒ Object
- #delete_in!(string) ⇒ Object
- #inversion(include_surrogates: false, upto: 0x10FFFF) ⇒ Object
- #keep_in(string) ⇒ Object
- #keep_in!(string) ⇒ Object
- #ranges ⇒ Object
- #sample(count = nil) ⇒ Object
- #used_by?(string) ⇒ Boolean
Instance Method Details
#case_insensitive ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 24 def case_insensitive new_set = dup each do |cp| swapped_cps = cp.chr('utf-8').swapcase.codepoints swapped_cps.size == 1 && new_set << swapped_cps[0] end new_set end |
#cover?(string) ⇒ Boolean
47 48 49 50 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 47 def cover?(string) str!(string).each_codepoint { |cp| return false unless include?(cp) } true end |
#delete_in(string) ⇒ Object
52 53 54 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 52 def delete_in(string) make_new_str(string) { |cp, new_str| include?(cp) || (new_str << cp) } end |
#delete_in!(string) ⇒ Object
56 57 58 59 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 56 def delete_in!(string) result = delete_in(string) result.size == string.size ? nil : string.replace(result) end |
#inversion(include_surrogates: false, upto: 0x10FFFF) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 15 def inversion(include_surrogates: false, upto: 0x10FFFF) new_set = self.class.new 0.upto(upto) do |cp| next unless include_surrogates || cp > 0xDFFF || cp < 0xD800 new_set << cp unless include?(cp) end new_set end |
#keep_in(string) ⇒ Object
61 62 63 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 61 def keep_in(string) make_new_str(string) { |cp, new_str| include?(cp) && (new_str << cp) } end |
#keep_in!(string) ⇒ Object
65 66 67 68 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 65 def keep_in!(string) result = keep_in(string) result.size == string.size ? nil : string.replace(result) end |
#ranges ⇒ Object
33 34 35 36 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 33 def ranges @range_compressor_required ||= require 'range_compressor' RangeCompressor.compress(self) end |
#sample(count = nil) ⇒ Object
38 39 40 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 38 def sample(count = nil) count.nil? ? to_a(true).sample : to_a(true).sample(count) end |
#used_by?(string) ⇒ Boolean
42 43 44 45 |
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 42 def used_by?(string) str!(string).each_codepoint { |cp| return true if include?(cp) } false end |