Class: Archaeo::CdxFilter
- Inherits:
-
Object
- Object
- Archaeo::CdxFilter
- Defined in:
- lib/archaeo/cdx_filter.rb
Overview
Builds and validates CDX Server API filter expressions.
CDX filter format: [!]field:regex The optional ! prefix inverts the match. The field must be a recognized CDX field name. The regex is a Java-compatible regex pattern matched against the field value.
Constant Summary collapse
- VALID_FIELDS =
%w[ urlkey timestamp original mimetype statuscode digest length ].freeze
Class Method Summary collapse
- .by_digest(digest) ⇒ Object
- .by_mimetype(type) ⇒ Object
- .by_status(code) ⇒ Object
- .by_url(pattern) ⇒ Object
- .excluding_mimetype(type) ⇒ Object
- .excluding_status(code) ⇒ Object
Instance Method Summary collapse
- #field ⇒ Object
-
#initialize(expression) ⇒ CdxFilter
constructor
A new instance of CdxFilter.
- #negated? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(expression) ⇒ CdxFilter
Returns a new instance of CdxFilter.
16 17 18 19 |
# File 'lib/archaeo/cdx_filter.rb', line 16 def initialize(expression) @expression = expression.to_s validate! end |
Class Method Details
.by_digest(digest) ⇒ Object
50 51 52 |
# File 'lib/archaeo/cdx_filter.rb', line 50 def self.by_digest(digest) new("digest:#{digest}") end |
.by_mimetype(type) ⇒ Object
42 43 44 |
# File 'lib/archaeo/cdx_filter.rb', line 42 def self.by_mimetype(type) new("mimetype:#{type}") end |
.by_status(code) ⇒ Object
34 35 36 |
# File 'lib/archaeo/cdx_filter.rb', line 34 def self.by_status(code) new("statuscode:#{code}") end |
.by_url(pattern) ⇒ Object
54 55 56 |
# File 'lib/archaeo/cdx_filter.rb', line 54 def self.by_url(pattern) new("original:#{pattern}") end |
.excluding_mimetype(type) ⇒ Object
46 47 48 |
# File 'lib/archaeo/cdx_filter.rb', line 46 def self.excluding_mimetype(type) new("!mimetype:#{type}") end |
.excluding_status(code) ⇒ Object
38 39 40 |
# File 'lib/archaeo/cdx_filter.rb', line 38 def self.excluding_status(code) new("!statuscode:#{code}") end |
Instance Method Details
#field ⇒ Object
29 30 31 32 |
# File 'lib/archaeo/cdx_filter.rb', line 29 def field stripped = @expression.delete_prefix("!") stripped.split(":", 2).first.to_s end |
#negated? ⇒ Boolean
25 26 27 |
# File 'lib/archaeo/cdx_filter.rb', line 25 def negated? @expression.start_with?("!") end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/archaeo/cdx_filter.rb', line 21 def to_s @expression end |