Sha256: d305b9e0b6e4520aaacd53c269dc38134ee854dc82cdbafceb63976c39f337f4

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

class String
  BLANK_RE = /\A[[:space:]]*\z/

  def blank?
    empty? || BLANK_RE === self || self == "\u001A"
  end

  def indent(spaces = 2)
    lines.map { |line| " " * spaces + line }.join
  end

  def inline_dcm
    "KONSERVIERUNG_FORMAT 2.0\n\n" + self
  end

  def enquote
    "\"#{to_s}\""
  end

  def to_si
    [self].pack("H*").unpack("l>").first
  end

  def delete_surrounding(char)
    self.delete_prefix(char).delete_suffix(char)
  end

  def to_regexp(ignorecase: false, multiline: false, extended: false)
    options = 0
    options = options | Regexp::EXTENDED   if extended
    options = options | Regexp::IGNORECASE if ignorecase
    options = options | Regexp::MULTILINE  if multiline
    Regexp.new(self, options)
  end
end

class Regexp
  def extract_captures(str)
    data = match(str)
    return {} if data.nil?
    data.named_captures.symbolize_keys
  end
end

class Array
  def avg
    empty? ? nil : sum.to_f / count
  end
end

class Hash
  def symbolize_keys
    self.map { |k, v| [k.to_sym, v] }.to_h
  end
end

class File
  def self.read_encoded(filepath)
    read(filepath).encode('UTF-8', 'ISO-8859-1', invalid: :replace, undef: :replace, replace: '')
    #read(filepath)
  end
end

class Range
  def overlaps?(other)
    max >= other.min && min <= other.min ||
    other.max >= min && other.min <= min
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
automotive-ecu-0.1.9 lib/core_ext.rb
automotive-ecu-0.1.8 lib/core_ext.rb
automotive-ecu-0.1.7 lib/core_ext.rb
automotive-ecu-0.1.6 lib/core_ext.rb
automotive-ecu-0.1.5 lib/core_ext.rb
automotive-ecu-0.1.4 lib/core_ext.rb
automotive-ecu-0.1.3 lib/core_ext.rb
automotive-ecu-0.1.2 lib/core_ext.rb
automotive-ecu-0.1.1 lib/core_ext.rb
automotive-ecu-0.1.0 lib/core_ext.rb