Sha256: 1ba3871fc7557ff50ec8e518a2a2fc64b6c514d0979094078cd557ca0946f564

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

class String

  # string formatting for ruby 1.8
  def format(params)
    if params.is_a? Hash
      array_params = self.scan(/%[<{]([^>}]*)[>}]/).collect do |name|
        name = name[0]
        params[name.to_s] || params[name.to_sym]
      end

      self.gsub(/%[<{]([^>}]*)[>}]/, '%') % array_params
    else
      self % params
    end
  end

  def camelize()
    return self if self !~ /_/ && self =~ /[A-Z]+.*/
    split('_').map{|e| e.capitalize}.join
  end

  def indent_with(indent_str)
    gsub(/^/, indent_str)
  end

end

module HammerCLI

  def self.interactive?
    return false unless STDOUT.tty?
    return HammerCLI::Settings.get(:_params, :interactive) unless HammerCLI::Settings.get(:_params, :interactive).nil?
    HammerCLI::Settings.get(:ui, :interactive) != false
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hammer_cli-0.1.0 lib/hammer_cli/utils.rb