Class: Stamp::Emitters::Lookup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, lookup = nil) ⇒ Lookup

Returns a new instance of Lookup.

Parameters:

  • the (field)

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

  • an (lookup)

    array of the string values to be formatted (e.g. +Date::DAYNAMES+) or a +call+able that returns the formatted value



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

def initialize(field, lookup=nil)
  @field = field
  @lookup = lookup
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

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
21
22
23
24
# File 'lib/stamp/emitters/lookup.rb', line 18

def lookup(value)
  if @lookup.respond_to?(:call)
    @lookup.call(value)
  else
    @lookup[value]
  end
end