Module: HashEngine::Format

Included in:
HashEngine, Actions, Extract, Transform
Defined in:
lib/hash_engine/format.rb

Constant Summary collapse

@@formats =
{}

Instance Method Summary collapse

Instance Method Details

#add_format(name, &block) ⇒ Object



12
13
14
# File 'lib/hash_engine/format.rb', line 12

def add_format name, &block
  @@formats[name] = block
end

#format(data, format_instructions) ⇒ Object

leverage the fact that procs and hash have a common interface



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hash_engine/format.rb', line 17

def format(data, format_instructions)
  if format_instructions.is_a?(Hash) &&
     format_instructions.has_key?('strftime') &&
     data.respond_to?(:strftime) then
    data.send(:strftime, format_instructions['strftime'])
  elsif formats.has_key?(format_instructions)
    formats[format_instructions][data]
  else
    data
  end
end

#formatsObject



8
9
10
# File 'lib/hash_engine/format.rb', line 8

def formats
  @@formats
end