Module: StringHelper
- Included in:
- Worklog, WorklogCLI
- Defined in:
- worklog/string_helper.rb
Overview
Helpers for String manipulation
Instance Method Summary collapse
-
#format_left(string) ⇒ String
Format a string to be left-aligned in a fixed-width field.
-
#pluralize(count, singular, plural = nil) ⇒ String
Pluralize a word based on a count.
Instance Method Details
#format_left(string) ⇒ String
Format a string to be left-aligned in a fixed-width field
32 33 34 |
# File 'worklog/string_helper.rb', line 32 def format_left(string) format('%18s', string) end |
#pluralize(count, singular, plural = nil) ⇒ String
Pluralize a word based on a count. If the plural form is irregular, it can be provided. Otherwise, it will be generated automatically.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'worklog/string_helper.rb', line 12 def pluralize(count, singular, plural = nil) if count == 1 singular else return plural if plural return "#{singular[0..-2]}ies" if singular.end_with? 'y' return "#{singular}es" if singular.end_with? 'ch', 's', 'sh', 'x', 'z' return "#{singular[0..-2]}ves" if singular.end_with? 'f', 'fe' "#{singular}s" end end |