Class: String
- Inherits:
-
Object
- Object
- String
- Includes:
- Doing::Color
- Defined in:
- lib/doing/string.rb,
lib/doing/string_chronify.rb,
lib/doing/template_string.rb
Overview
Chronify methods for strings
Direct Known Subclasses
Constant Summary
Constants included from Doing::Color
Doing::Color::ATTRIBUTES, Doing::Color::ATTRIBUTE_NAMES, Doing::Color::COLORED_REGEXP
Instance Method Summary collapse
-
#add_at ⇒ String
Add @ prefix to string if needed, maintains +/- prefix.
-
#add_tags(tags, remove: false) ⇒ String
The tagged string.
- #add_tags!(tags, remove: false) ⇒ Object
-
#cap_first ⇒ Object
Capitalize on the first character on string.
-
#chronify(**options) ⇒ DateTime
Converts input string into a Time object when input takes on the following formats: - interval format e.g.
-
#chronify_qty ⇒ Integer
Converts simple strings into seconds that can be added to a Time object.
-
#clean_unlinked_urls ⇒ Object
Clean up unlinked
. -
#compress ⇒ Object
Compress multiple spaces to single space.
- #compress! ⇒ Object
-
#dedup_tags ⇒ Object
Remove duplicate tags, leaving only first occurrence.
- #dedup_tags! ⇒ Object
-
#expand_date_tags(additional_tags = nil) ⇒ Object
Convert (chronify) natural language dates within configured date tags (tags whose value is expected to be a date).
-
#highlight_tags(color = 'yellow', last_color: nil) ⇒ String
Colorize @tags with ANSI escapes.
- #highlight_tags!(color = 'yellow', last_color: nil) ⇒ Object
-
#ignore? ⇒ Boolean
Test if line should be ignored.
-
#is_rx? ⇒ Boolean
Determines if receiver is surrounded by slashes or starts with single quote.
-
#last_color ⇒ String
Returns the last escape sequence from a string.
-
#link_urls(**opt) ⇒ Object
Turn raw urls into HTML links.
- #link_urls!(**opt) ⇒ Object
-
#normalize_age(default = :newest) ⇒ Symbol
Convert an age string to a qualified type.
- #normalize_age!(default = :newest) ⇒ Object
-
#normalize_bool(default = :and) ⇒ Object
Convert a boolean string to a symbol.
- #normalize_bool!(default = :and) ⇒ Object
-
#normalize_case(default = :smart) ⇒ Object
Convert a case sensitivity string to a symbol.
- #normalize_case! ⇒ Object
-
#normalize_matching(default = :pattern) ⇒ Object
Convert a matching configuration string to a symbol.
- #normalize_matching!(default = :pattern) ⇒ Object
- #normalize_order(default = 'asc') ⇒ Object
-
#normalize_order!(default = 'asc') ⇒ String
Convert a sort order string to a qualified type.
-
#normalize_trigger ⇒ String
Adds ?: to any parentheticals in a regular expression to avoid match groups.
- #normalize_trigger! ⇒ Object
-
#remove_self_links ⇒ Object
Remove
formatting. -
#replace_qualified_urls(**options) ⇒ Object
Replace qualified urls.
-
#set_type(kind = nil) ⇒ Object
Convert a string value to an appropriate type.
- #simple_wrap(width) ⇒ Object
-
#tag(tag, value: nil, remove: false, rename_to: nil, regex: false, single: false, force: false) ⇒ String
Add, rename, or remove a tag.
-
#tag!(tag, **options) ⇒ Object
Add, rename, or remove a tag in place.
-
#time_string(format: :dhm) ⇒ Object
Convert DD:HH:MM to a natural language string.
-
#to_p(number) ⇒ Object
Pluralize a string based on quantity.
-
#to_rx(distance: nil, case_type: nil) ⇒ Regexp
Convert string to fuzzy regex.
-
#to_seconds ⇒ Integer
Convert DD:HH:MM to seconds.
-
#to_tags ⇒ Array
Convert a list of tags to an array.
-
#truncate(len, ellipsis: '...') ⇒ Object
Truncate to nearest word.
- #truncate!(len, ellipsis: '...') ⇒ Object
-
#truncmiddle(len, ellipsis: '...') ⇒ Object
Truncate string in the middle.
- #truncmiddle!(len, ellipsis: '...') ⇒ Object
-
#truthy? ⇒ Boolean
Test string for truthiness (0, "f", "false", "n", "no" all return false, case insensitive, otherwise true).
-
#uncolor ⇒ Object
Remove color escape codes.
- #uncolor! ⇒ Object
-
#validate_color ⇒ String
private
Extract the longest valid color from a string.
-
#wildcard_to_rx ⇒ String
Convert ? and * wildcards to regular expressions.
-
#wrap(len, pad: 0, indent: ' ', offset: 0, prefix: '', color: '', after: '', reset: '', pad_first: false) ⇒ Object
Wrap string at word breaks, respecting tags.
Methods included from Doing::Color
attributes, coloring?, #support?
Instance Method Details
#add_at ⇒ String
Add @ prefix to string if needed, maintains +/- prefix
#add_tags(tags, remove: false) ⇒ String
Returns the tagged string.
#add_tags!(tags, remove: false) ⇒ Object
#cap_first ⇒ Object
Capitalize on the first character on string
#chronify(**options) ⇒ DateTime
Converts input string into a Time object when input takes on the following formats: - interval format e.g. '1d2h30m', '45m' etc. - a semantic phrase e.g. 'yesterday 5:30pm' - a strftime e.g. '2016-03-15 15:32:04 PDT'
#chronify_qty ⇒ Integer
Converts simple strings into seconds that can be added to a Time object
Input string can be HH:MM or XX[dhm][XXhm][XXm]
#clean_unlinked_urls ⇒ Object
Clean up unlinked
#compress ⇒ Object
Compress multiple spaces to single space
#compress! ⇒ Object
#dedup_tags ⇒ Object
Remove duplicate tags, leaving only first occurrence
#dedup_tags! ⇒ Object
#expand_date_tags(additional_tags = nil) ⇒ Object
Convert (chronify) natural language dates within configured date tags (tags whose value is expected to be a date). Modifies string in place.
#highlight_tags(color = 'yellow', last_color: nil) ⇒ String
Colorize @tags with ANSI escapes
#highlight_tags!(color = 'yellow', last_color: nil) ⇒ Object
#ignore? ⇒ Boolean
Test if line should be ignored
#is_rx? ⇒ Boolean
Determines if receiver is surrounded by slashes or starts with single quote
#last_color ⇒ String
Returns the last escape sequence from a string.
Actually returns all escape codes, with the assumption that the result of inserting them will generate the same color as was set at the end of the string. Because you can send modifiers like dark and bold separate from color codes, only using the last code may not render the same style.
#link_urls(**opt) ⇒ Object
Turn raw urls into HTML links
:html (default)
#link_urls!(**opt) ⇒ Object
#normalize_age(default = :newest) ⇒ Symbol
Convert an age string to a qualified type
#normalize_age!(default = :newest) ⇒ Object
#normalize_bool(default = :and) ⇒ Object
Convert a boolean string to a symbol
#normalize_bool!(default = :and) ⇒ Object
#normalize_case(default = :smart) ⇒ Object
Convert a case sensitivity string to a symbol
#normalize_case! ⇒ Object
#normalize_matching(default = :pattern) ⇒ Object
Convert a matching configuration string to a symbol
#normalize_matching!(default = :pattern) ⇒ Object
#normalize_order(default = 'asc') ⇒ Object
#normalize_order!(default = 'asc') ⇒ String
Convert a sort order string to a qualified type
#normalize_trigger ⇒ String
Adds ?: to any parentheticals in a regular expression to avoid match groups
#normalize_trigger! ⇒ Object
#remove_self_links ⇒ Object
Remove
#replace_qualified_urls(**options) ⇒ Object
Replace qualified urls
#set_type(kind = nil) ⇒ Object
Convert a string value to an appropriate type. If kind is not specified, '[one, two]' becomes an Array, '1' becomes Integer, '1.5' becomes Float, 'true' or 'yes' becomes TrueClass, 'false' or 'no' becomes FalseClass.
#simple_wrap(width) ⇒ Object
#tag(tag, value: nil, remove: false, rename_to: nil, regex: false, single: false, force: false) ⇒ String
Add, rename, or remove a tag
#tag!(tag, **options) ⇒ Object
Add, rename, or remove a tag in place
#time_string(format: :dhm) ⇒ Object
Convert DD:HH:MM to a natural language string
#to_p(number) ⇒ Object
Pluralize a string based on quantity
#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.
#to_seconds ⇒ Integer
Convert DD:HH:MM to seconds
#to_tags ⇒ Array
Convert a list of tags to an array. Tags can be with or without @ symbols, separated by any character, and can include parenthetical values (with spaces)
#truncate(len, ellipsis: '...') ⇒ Object
Truncate to nearest word
#truncate!(len, ellipsis: '...') ⇒ Object
#truncmiddle(len, ellipsis: '...') ⇒ Object
Truncate string in the middle
#truncmiddle!(len, ellipsis: '...') ⇒ Object
#truthy? ⇒ Boolean
Test string for truthiness (0, "f", "false", "n", "no" all return false, case insensitive, otherwise true)
#uncolor ⇒ Object
Remove color escape codes
#uncolor! ⇒ Object
#validate_color ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extract the longest valid color from a string.
Allows %colors to bleed into other text and still be recognized, e.g. %greensomething still finds %green.
#wildcard_to_rx ⇒ String
Convert ? and * wildcards to regular expressions. Uses \S (non-whitespace) instead of . (any character)
#wrap(len, pad: 0, indent: ' ', offset: 0, prefix: '', color: '', after: '', reset: '', pad_first: false) ⇒ Object
Wrap string at word breaks, respecting tags