Module: Doing::StringQuery

Included in:
String
Defined in:
lib/doing/string/query.rb

Overview

Handling of search and regex strings

Instance Method Summary collapse

Instance Method Details

#ignore?Boolean

Test if line should be ignored

Returns:

  • (Boolean)

    line is empty or comment

#ignore_case(search, case_type) ⇒ Boolean

Determine whether case should be ignored for string

Parameters:

  • search

    The search string

  • case_type

    The case type, :smart, :sensitive, :ignore

Returns:

  • (Boolean)

    true if case should be ignored

#rx?Boolean

Determines if receiver is surrounded by slashes or starts with single quote

Returns:

  • (Boolean)

    True if regex, False otherwise.

#to_boolBoolean

Returns a bool representation of the string.

Returns:

  • (Boolean)

    Bool representation of the object.

#to_phrase_queryObject

Returns a phrase query (elastic search) representation of the object as a phrase parser.

Returns:

  • Phrase query representation of the object.

#to_queryObject

Returns a query (elastic search) representation of the object as a boolean term parser.

Returns:

  • Query representation of the object.

#to_rx(distance: nil, case_type: nil) ⇒ Regexp

Convert string to fuzzy regex. Characters in words can be separated by up to distance characters in haystack, spaces indicate unlimited distance.

Examples:

"this word".to_rx(3)
# => /t.{0,3}h.{0,3}i.{0,3}s.{0,3}.*?w.{0,3}o.{0,3}r.{0,3}d/

Parameters:

  • distance (Integer) (defaults to: nil)

    Allowed distance between characters

  • case_type (defaults to: nil)

    The case type

Returns:

  • (Regexp)

    Regex pattern

#truthy?Boolean

Test string for truthiness (0, "f", "false", "n", "no" all return false, case insensitive, otherwise true)

Returns:

  • (Boolean)

    String is truthy

#wildcard_to_rxString

Convert ? and * wildcards to regular expressions. Uses \S (non-whitespace) instead of . (any character)

Returns:

  • (String)

    Regular expression string