Sha256: 5f281ec97563f55bb6f04440b494bbe0834d398f5c3eceaff1f99aa197cf6a51

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

require 'yaml'
require 'fileutils'
module MetricFu
  module Utility
    module_function

    # Removes non-ASCII characters
    def clean_ascii_text(text)
      if text.respond_to?(:encode)
        # avoids invalid multi-byte escape error
        ascii_text = text.encode( 'ASCII', invalid: :replace, undef: :replace, replace: '' )
        # see http://www.ruby-forum.com/topic/183413
        pattern = Regexp.new('[\x80-\xff]', nil, 'n')
        ascii_text.gsub(pattern, '')
      else
        text
      end
    end

    def rm_rf(*args)
      FileUtils.rm_rf(*args)
    end

    def mkdir_p(*args)
      FileUtils.mkdir_p(*args)
    end

    def glob(*args)
      Dir.glob(*args)
    end

    def load_yaml(file)
      YAML.load_file(file)
    end

    def binread(file)
      File.binread(file)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metric_fu-4.7.2 lib/metric_fu/utility.rb
metric_fu-4.7.1 lib/metric_fu/utility.rb
metric_fu-4.7.0 lib/metric_fu/utility.rb