Class: TimeSymbol
- Inherits:
-
Object
- Object
- TimeSymbol
- Defined in:
- lib/dated_backup/extensions/time_symbol.rb
Overview
Used to change the the TimeSymbols (:year, :month, :day, and :week) into the various natural language forms (the symbols singular, plural, and adverb).
Initialize with the singular symbol name, or call TimeSymbol.valid_symbols to give an array of valid symbols.
Constant Summary collapse
- VALID_TIME_COMPONENTS =
[:year, :month, :week, :day]
Class Method Summary collapse
- .all ⇒ Object (also: valid_symbols)
Instance Method Summary collapse
- #adverb ⇒ Object (also: #to_adverb)
-
#initialize(sym) ⇒ TimeSymbol
constructor
A new instance of TimeSymbol.
- #inspect ⇒ Object
- #plural ⇒ Object (also: #to_plural)
- #plural_adverb ⇒ Object (also: #to_plural_adverb)
- #singular ⇒ Object (also: #to_singular)
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(sym) ⇒ TimeSymbol
Returns a new instance of TimeSymbol.
17 18 19 20 21 22 23 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 17 def initialize(sym) if VALID_TIME_COMPONENTS.include? sym @sym = sym else raise TimeSymbolError, "The symbol given must be a valid TimeSymbol (:year, :month, :week, or :day)" end end |
Class Method Details
.all ⇒ Object Also known as: valid_symbols
10 11 12 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 10 def all VALID_TIME_COMPONENTS.dup end |
Instance Method Details
#adverb ⇒ Object Also known as: to_adverb
37 38 39 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 37 def adverb @sym == :day ? :daily : "#{@sym}ly".to_sym end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 57 def inspect @sym.inspect end |
#plural ⇒ Object Also known as: to_plural
31 32 33 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 31 def plural "#{@sym}s".to_sym end |
#plural_adverb ⇒ Object Also known as: to_plural_adverb
43 44 45 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 43 def plural_adverb @sym == :day ? :dailies : "#{@sym}lies".to_sym end |
#singular ⇒ Object Also known as: to_singular
25 26 27 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 25 def singular @sym end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 53 def to_s @sym.to_s end |
#to_sym ⇒ Object
49 50 51 |
# File 'lib/dated_backup/extensions/time_symbol.rb', line 49 def to_sym @sym.to_sym end |