Sha256: 628a51d2d6da3306b1dad4662a2ad38a2bd5497c4ce36f5da36ad366bc053f03

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

module Kosher

  # The seller's description of the offer.
  class Description < Structure
    key :text, :default => ''

    DAMAGED     = "\\b(?:missing|torn|broken|split|discard|withdrawn|rent|stain|school|damaged|water)"
    EXLIB       = "(?:e?x|discarded|retired|former|has|have)[\\s._-]*lib"
    MARKED      = "(highlight|hilit|underlin)"
    MISSING_VOL = "(vols?|volume) only"
    REVIEW_COPY = "\\b(?:uncorrected|advanced?\\sreview|arc)\\b"

    def damaged?
      matches? DAMAGED
    end

    def ex_lib?
      matches?(EXLIB) && !matches?(negation_of(EXLIB))
    end

    def kosher?
      !damaged? && !ex_lib? && !marked? && !missing_volume? && !review_copy?
    end

    def marked?
      matches?(MARKED) && !matches?(negation_of(MARKED))
    end

    def missing_volume?
      matches? MISSING_VOL
    end

    def review_copy?
      matches? REVIEW_COPY
    end

    private

    def matches?(value)
      !!text.match(Regexp.new(value, true))
    end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kosher-0.8.0 lib/kosher/description.rb
kosher-0.7.0 lib/kosher/description.rb
kosher-0.6.2 lib/kosher/description.rb
kosher-0.6.1 lib/kosher/description.rb
kosher-0.6.0 lib/kosher/description.rb
kosher-0.5.0 lib/kosher/description.rb
kosher-0.4.0 lib/kosher/description.rb
kosher-0.3.0 lib/kosher/description.rb