lib/accept_headers/acceptable.rb in accept_headers-0.0.4 vs lib/accept_headers/acceptable.rb in accept_headers-0.0.5

- old
+ new

@@ -3,14 +3,26 @@ class Error < StandardError; end class InvalidQError < Error; end attr_reader :q - def match(other) - raise NotImplementedError.new("#match is not implemented") + def reject?(other) + if q != 0.0 + false + else + match(other) + end end + def accept?(other) + if q == 0.0 + false + else + match(other) + end + end + def q=(value) begin q_float = Float(value) rescue ArgumentError => e raise InvalidQError.new(e.message) @@ -20,8 +32,13 @@ end if q_float.to_s.match(/^\d\.(\d+)$/) && $1 && $1.size > 3 raise InvalidQError.new("q must be at most 3 decimal places") end @q = q_float + end + + private + def match(other) + raise NotImplementedError.new("#match is not implemented") end end end