_plugins/eiti_data.rb
def format_url(format, data)
      placeholder = '%'
      pattern = /:\w+/
      if data.is_a?(Hash)
        if !format.match(pattern) && format.include?(placeholder)
          return format.gsub(placeholder, data['id'])
        else
          return format.gsub(pattern) { |k| data[k[1..k.size]] }
        end
      elsif data.is_a?(String)
        unless format.include?(placeholder)
          puts "format_url('#{format}', '#{data}':String): " \
            "no placeholder '#{placeholder}'"
        end
        return format.gsub(placeholder, data)
      else
        return format
      end
    end
# formats a URL-like string with either a data Hash or a
# placeholder string:
#
# >> EITI::Data.format_url('foo/:bar/baz', {'bar' => 'x'})
# => 'foo/x/baz'
# >> EITI::Data.format_url('foo/%/baz', {'id' => 'x'})
# => 'foo/x/baz'
# >> EITI::Data.format_url('foo/%/baz', 'x')
# => 'foo/x/baz'
formats a URL-like string with either a data Hash or a
placeholder string.


formats a URL - like string with either a data Hash or a placeholder string .
def format_url(format, data)
      placeholder = '%'
      pattern = /:\w+/
      if data.is_a?(Hash)
        if !format.match(pattern) && format.include?(placeholder)
          return format.gsub(placeholder, data['id'])
        else
          return format.gsub(pattern) { |k| data[k[1..k.size]] }
        end
      elsif data.is_a?(String)
        unless format.include?(placeholder)
          puts "format_url('#{format}', '#{data}':String): " \
            "no placeholder '#{placeholder}'"
        end
        return format.gsub(placeholder, data)
      else
        return format
      end
    end
def format_url ( format , data ) placeholder = '%' pattern = / : \w + / if data . is_a? ( Hash ) if ! format . match ( pattern ) && format . include? ( placeholder ) return format . gsub ( placeholder , data [ 'id' ] ) else return format . gsub ( pattern ) { | k | data [ k [ 1 .. k . size ] ] } end elsif data . is_a? ( String ) unless format . include? ( placeholder ) puts "format_url('#{format}', '#{data}':String): " "no placeholder '#{placeholder}'" end return format . gsub ( placeholder , data ) else return format end end
formats a URL-like string with either a data Hash or a
placeholder string:
formats a URL - like string with either a data Hash or a placeholder string :
format
data