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
- .by_urlkey(pattern) ⇒ Object
- .combine(*filters) ⇒ Object
- .excluding_errors ⇒ Object
- .excluding_mimetype(type) ⇒ Object
- .excluding_status(code) ⇒ Object
- .only_successful ⇒ Object
Instance Method Summary collapse
- #and(other) ⇒ Object
- #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 |
.by_urlkey(pattern) ⇒ Object
58 59 60 |
# File 'lib/archaeo/cdx_filter.rb', line 58 def self.by_urlkey(pattern) new("urlkey:#{pattern}") end |
.combine(*filters) ⇒ Object
66 67 68 |
# File 'lib/archaeo/cdx_filter.rb', line 66 def self.combine(*filters) filters.flatten end |
.excluding_errors ⇒ Object
74 75 76 77 |
# File 'lib/archaeo/cdx_filter.rb', line 74 def self.excluding_errors [excluding_status(404), excluding_status(500), excluding_status(502), excluding_status(503)] 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 |
.only_successful ⇒ Object
70 71 72 |
# File 'lib/archaeo/cdx_filter.rb', line 70 def self.only_successful [by_status(200)] end |
Instance Method Details
#and(other) ⇒ Object
62 63 64 |
# File 'lib/archaeo/cdx_filter.rb', line 62 def and(other) [self, other] end |
#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 |