Sha256: a34300962ff3e14bc669723b31189ee2513a00343e0852ac63917328fb8527b6

Contents?: true

Size: 827 Bytes

Versions: 3

Compression:

Stored size: 827 Bytes

Contents

module Kosher
  class String < String
    def kosher?
      !(present? && (
        damaged?        ||
        ex_library?     ||
        marked?         ||
        missing_volume? ||
        review_copy?))
    end

    private

    def expect(str)
      !!match(Regexp.new(str, true))
    end

    def do_not_expect(str)
      !match(Regexp.new(str, true))
    end

    def damaged?
      expect(DAMAGED)
    end

    def ex_library?
      expect(EXLIBRARY) && do_not_expect(negation_of(EXLIBRARY))
    end

    def marked?
      expect(MARKED) && do_not_expect(negation_of(MARKED))
    end

    def missing_volume?
      expect(MISSING_VOL)
    end

    def negation_of(str)
      "(?:no|not an?)\\s+#{str}"
    end

    def present?
      self != ''
    end

    def review_copy?
      expect(REVIEW_COPY)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kosher-0.0.3 lib/kosher/string.rb
kosher-0.0.2 lib/kosher/string.rb
kosher-0.0.1 lib/kosher/string.rb