Class: BluepanClient::ApplyVars

Inherits:
Object
  • Object
show all
Defined in:
lib/bluepan_client/services/apply_vars.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(string, object) ⇒ Object



8
9
10
# File 'lib/bluepan_client/services/apply_vars.rb', line 8

def self.call(string, object)
  self.new(string: string, object: object).()
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
# File 'lib/bluepan_client/services/apply_vars.rb', line 12

def call
  matches = string.scan(/:\w+/)
  matches.reduce(string) do |str, var|
    method_name = var.gsub(":", "")
    value = object.send(method_name)
    str.gsub(var, value.to_s)
  end
end