Class: TimeSymbol

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

.allObject 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

#adverbObject 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

#inspectObject



57
58
59
# File 'lib/dated_backup/extensions/time_symbol.rb', line 57

def inspect
  @sym.inspect
end

#pluralObject 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_adverbObject 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

#singularObject Also known as: to_singular



25
26
27
# File 'lib/dated_backup/extensions/time_symbol.rb', line 25

def singular
  @sym
end

#to_sObject



53
54
55
# File 'lib/dated_backup/extensions/time_symbol.rb', line 53

def to_s
  @sym.to_s
end

#to_symObject



49
50
51
# File 'lib/dated_backup/extensions/time_symbol.rb', line 49

def to_sym
  @sym.to_sym
end