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



33
34
35
36
37
38
39
# File 'lib/dated_backup/extensions/time_symbol.rb', line 33

def adverb
  if @sym == :day
    :daily
  else
    "#{@sym}ly".to_sym
  end
end

#inspectObject



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

def inspect
  @sym.inspect
end

#pluralObject



29
30
31
# File 'lib/dated_backup/extensions/time_symbol.rb', line 29

def plural
  "#{@sym}s".to_sym
end

#singularObject



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

def singular
  @sym
end

#to_sObject



45
46
47
# File 'lib/dated_backup/extensions/time_symbol.rb', line 45

def to_s
  @sym.to_s
end

#to_symObject



41
42
43
# File 'lib/dated_backup/extensions/time_symbol.rb', line 41

def to_sym
  @sym.to_sym
end