module UselessString::WithOnlyStarter

Public Instance Methods

cmp_with_only(other_str, options = {}) click to toggle source
# File lib/with_only_starter.rb, line 8
def cmp_with_only(other_str, options = {})
  remove_extras(str = dup, other = other_str.dup, create_regex(options))
  options[:case_insensitive] ? str.casecmp(other) : str <=> other
end
eql_with_only?(other_str, options = {}) click to toggle source
# File lib/with_only_starter.rb, line 3
def eql_with_only?(other_str, options = {})
  remove_extras(str = dup, other = other_str.dup, create_regex(options))
  options[:case_insensitive] ? str.casecmp(other.upcase).zero? : str.eql?(other)
end

Private Instance Methods

create_regex(options) click to toggle source
# File lib/with_only_starter.rb, line 15
def create_regex(options)
  reg = '[^'
  reg += '\d' if options[:numbers]
  reg += 'a-zA-Z' if options[:alphabets]
  reg += ']'
  Regexp.new(reg)
end
remove_extras(str, other_str, regex) click to toggle source
# File lib/with_only_starter.rb, line 23
def remove_extras(str, other_str, regex)
  str.gsub!(regex, '')
  other_str.gsub!(regex, '')
end