Class: RemoteModule::FormatableString

Inherits:
String
  • Object
show all
Defined in:
lib/remote_model/formatable_string.rb

Instance Method Summary collapse

Methods inherited from String

#pluralize, #singularize

Instance Method Details

#format(params = {}, delegate = nil) ⇒ Object

Takes in a hash and spits out the formatted string Checks the delegate first



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/remote_model/formatable_string.rb', line 5

def format(params = {}, delegate = nil)
  params ||= {}
  split = self.split '/'
  split.collect { |path|
    ret = path
    if path[0] == ':'
      path_sym = path[1..-1].to_sym

      curr = nil
      if delegate && delegate.respond_to?(path_sym)
        curr = delegate.send(path_sym)
      end

      ret = (curr || params[path_sym] || path).to_s
    end

    ret
  }.join '/'
end