Class: TurboStreamer::KeyFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/turbostreamer/key_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ KeyFormatter

Returns a new instance of KeyFormatter.



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/turbostreamer/key_formatter.rb', line 2

def initialize(*args)
  @format = {}
  @cache = {}

  options = args.extract_options!
  args.each do |name|
    @format[name] = []
  end
  options.each do |name, paramaters|
    @format[name] = paramaters
  end
end

Instance Method Details

#format(key) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/turbostreamer/key_formatter.rb', line 19

def format(key)
  @cache[key] ||= @format.inject(key.to_s) do |result, args|
    func, args = args
    if ::Proc === func
      func.call result, *args
    else
      result.send func, *args
    end
  end
end

#initialize_copy(original) ⇒ Object



15
16
17
# File 'lib/turbostreamer/key_formatter.rb', line 15

def initialize_copy(original)
  @cache = {}
end