Sha256: 7672607849659d1604a80aaec1fd33e94107b379c68b51b9e64c3809844e02d1
Contents?: true
Size: 654 Bytes
Versions: 2
Compression:
Stored size: 654 Bytes
Contents
module Stamp module Emitters class Lookup attr_reader :field # @param [field] the field to be formatted (e.g. +:month+, +:year+) # @param [lookup] an array of the string values to be formatted (e.g. +Date::DAYNAMES+) # or a +call+able that returns the formatted value def initialize(field, lookup=nil) @field = field @lookup = lookup end def format(target) lookup(target.send(field)) end def lookup(value) if @lookup.respond_to?(:call) @lookup.call(value) else @lookup[value] end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stamp-0.6.0 | lib/stamp/emitters/lookup.rb |
stamp-0.5.0 | lib/stamp/emitters/lookup.rb |