Method: Chars::CharSet#strings_in

Defined in:
lib/chars/char_set.rb

#strings_in(data, options = {}) {|match, (index)| ... } ⇒ Array, Hash

Deprecated.

Use #each_substring_with_index, #substrings_with_index, #each_substring, or #substrings instead.

Finds sub-strings within given data that are made of characters within the Chars::CharSet.

Parameters:

  • data (String)

    The data to find sub-strings within.

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :length (Integer) — default: 4

    The minimum length of sub-strings found within the given data.

  • :offsets (Boolean) — default: false

    Specifies whether to return a Hash of offsets and matched sub-strings within the data, or to just return the matched sub-strings themselves.

Yields:

  • (match, (index))

    The given block will be passed every matched sub-string, and the optional index.

  • (String)

    match A sub-string containing the characters from the Chars::CharSet.

  • (Integer)

    index The index the sub-string was found at.

Returns:

  • (Array, Hash)

    If no block is given, an Array or Hash of sub-strings is returned.



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/chars/char_set.rb', line 574

def strings_in(data,options={},&block)
  kwargs = {min_length: options.fetch(:length,4)}

  unless block
    if options[:offsets]
      return Hash[substrings_with_indexes(data,**kwargs)]
    else
      return substrings(data,**kwargs)
    end
  end

  case block.arity
  when 2
    each_substring_with_index(data,**kwargs,&block)
  else
    each_substring(data,**kwargs,&block)
  end
end