Module: Birdwatcher::Concerns::Util
- Included in:
- Birdwatcher::Command, Module
- Defined in:
- lib/birdwatcher/concerns/util.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#escape_html(string) ⇒ String
Escape special HTML characters with HTML entities.
-
#excerpt(text, max_length, omission = "...") ⇒ String
Create an excerpt of potentially long text at a fixed length.
-
#parse_time(time) ⇒ Time
Natural language parsing of time.
-
#pluralize(count, singular, plural) ⇒ Object
Correct pluralization of word depending on count.
-
#strip_control_characters(string) ⇒ String
Strip out control characters and color codes from a string.
-
#strip_html(string) ⇒ String
Strip out HTML tags from a string.
-
#suppress_output(&block) ⇒ Object
Suppress any potential output to STDOUT.
-
#suppress_warnings(&block) ⇒ Object
Suppress any warning messages to STDOUT.
-
#time_ago_in_words(time) ⇒ String
Get the relative time for a timestamp.
-
#unescape_html(string) ⇒ String
Unescape special HTML characters in a string.
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/birdwatcher/concerns/util.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#escape_html(string) ⇒ String
Escape special HTML characters with HTML entities
86 87 88 |
# File 'lib/birdwatcher/concerns/util.rb', line 86 def escape_html(string) Birdwatcher::Util.escape_html(string) end |
#excerpt(text, max_length, omission = "...") ⇒ String
Create an excerpt of potentially long text at a fixed length
113 114 115 |
# File 'lib/birdwatcher/concerns/util.rb', line 113 def excerpt(text, max_length, omission = "...") Birdwatcher::Util.excerpt(text, max_length, omission) end |
#parse_time(time) ⇒ Time
Natural language parsing of time
Uses the Chronic gem to perform natural language parsing of time. See the examples in Chronic’s documentation for strings that can be parsed.
All modules that can be configured with times, should perform natural language parsing on the option setting for better user experience.
38 39 40 |
# File 'lib/birdwatcher/concerns/util.rb', line 38 def parse_time(time) Birdwatcher::Util.parse_time(time) end |
#pluralize(count, singular, plural) ⇒ Object
Correct pluralization of word depending on count
pluralizes the singular word unless count is 1.
59 60 61 |
# File 'lib/birdwatcher/concerns/util.rb', line 59 def pluralize(count, singular, plural) Birdwatcher::Util.pluralize(count, singular, plural) end |
#strip_control_characters(string) ⇒ String
Strip out control characters and color codes from a string
77 78 79 |
# File 'lib/birdwatcher/concerns/util.rb', line 77 def strip_control_characters(string) Birdwatcher::Util.strip_control_characters(string) end |
#strip_html(string) ⇒ String
Strip out HTML tags from a string
68 69 70 |
# File 'lib/birdwatcher/concerns/util.rb', line 68 def strip_html(string) Birdwatcher::Util.strip_html(string) end |
#suppress_output(&block) ⇒ Object
Suppress any potential output to STDOUT
Used in cases where certain libraries or methods might output unwanted text to STDOUT
without any possibility of disabling it.
123 124 125 |
# File 'lib/birdwatcher/concerns/util.rb', line 123 def suppress_output(&block) Birdwatcher::Util.suppress_output(&block) end |
#suppress_warnings(&block) ⇒ Object
Suppress any warning messages to STDOUT
Used in cases where certain libraries or methods might output unwanted warning messages to STDOUT
.
133 134 135 |
# File 'lib/birdwatcher/concerns/util.rb', line 133 def suppress_warnings(&block) Birdwatcher::Util.suppress_warnings(&block) end |
#time_ago_in_words(time) ⇒ String
Get the relative time for a timestamp
21 22 23 |
# File 'lib/birdwatcher/concerns/util.rb', line 21 def time_ago_in_words(time) Birdwatcher::Util.time_ago_in_words(time) end |
#unescape_html(string) ⇒ String
Unescape special HTML characters in a string
95 96 97 |
# File 'lib/birdwatcher/concerns/util.rb', line 95 def unescape_html(string) Birdwatcher::Util.unescape_html(string) end |