Class: Stamp::Emitters::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/stamp/emitters/lookup.rb

Constant Summary collapse

MONTH =
new(:month, Date::MONTHNAMES,      "%B")
ABBR_MONTH =
new(:month, Date::ABBR_MONTHNAMES, "%b")
DAY =
new(:wday,  Date::DAYNAMES,        "%A")
ABBR_DAY =
new(:wday,  Date::ABBR_DAYNAMES,   "%a")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, lookup, strftime_directive) ⇒ Lookup

Returns a new instance of Lookup.

Parameters:

  • field (Symbol|String)

    the field to be formatted (e.g. :month, :year)

  • lookup (Array<String>)

    an array of the string values to be formatted (e.g. Date::DAYNAMES)



8
9
10
11
12
# File 'lib/stamp/emitters/lookup.rb', line 8

def initialize(field, lookup, strftime_directive)
  @field = field
  @lookup = lookup
  @strftime_directive = strftime_directive
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



4
5
6
# File 'lib/stamp/emitters/lookup.rb', line 4

def field
  @field
end

#strftime_directiveObject (readonly)

Returns the value of attribute strftime_directive.



4
5
6
# File 'lib/stamp/emitters/lookup.rb', line 4

def strftime_directive
  @strftime_directive
end

Instance Method Details

#format(target) ⇒ Object



14
15
16
# File 'lib/stamp/emitters/lookup.rb', line 14

def format(target)
  lookup(target.send(field))
end

#lookup(value) ⇒ Object



18
19
20
# File 'lib/stamp/emitters/lookup.rb', line 18

def lookup(value)
  @lookup[value]
end