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