Class: ActiveMail::Quality::Guard
- Inherits:
-
Object
- Object
- ActiveMail::Quality::Guard
- Extended by:
- T::Sig
- Defined in:
- lib/activemail/quality/guard.rb
Defined Under Namespace
Classes: Violation
Constant Summary collapse
- DISABLEABLE =
T.let(%i[max_bytes parse_error table_role img_alt lang min_full_doc_bytes].freeze, T::Array[Symbol])
- DEFAULT_MAX_BYTES =
Gmail clips messages past ~102KB.
102_400- DEFAULT_MIN_FULL_DOC_BYTES =
A full HTML document smaller than this carries no real layout and is suspect.
1_024
Instance Method Summary collapse
-
#initialize(max_bytes: DEFAULT_MAX_BYTES, min_full_doc_bytes: DEFAULT_MIN_FULL_DOC_BYTES, disable: []) ⇒ Guard
constructor
A new instance of Guard.
- #valid?(html) ⇒ Boolean
- #violations(html) ⇒ Object
Constructor Details
#initialize(max_bytes: DEFAULT_MAX_BYTES, min_full_doc_bytes: DEFAULT_MIN_FULL_DOC_BYTES, disable: []) ⇒ Guard
Returns a new instance of Guard.
29 30 31 32 33 34 35 36 37 |
# File 'lib/activemail/quality/guard.rb', line 29 def initialize(max_bytes: DEFAULT_MAX_BYTES, min_full_doc_bytes: DEFAULT_MIN_FULL_DOC_BYTES, disable: []) # A non-positive threshold would silently disable (or invert) a check. @max_bytes = T.let(positive_threshold!(:max_bytes, max_bytes), Integer) @min_full_doc_bytes = T.let(positive_threshold!(:min_full_doc_bytes, min_full_doc_bytes), Integer) unknown = disable - DISABLEABLE raise ArgumentError, "unknown rule(s): #{unknown.inspect}, expected a subset of #{DISABLEABLE.inspect}" unless unknown.empty? @disabled = T.let(disable.to_set, T::Set[Symbol]) end |
Instance Method Details
#valid?(html) ⇒ Boolean
53 54 55 |
# File 'lib/activemail/quality/guard.rb', line 53 def valid?(html) violations(html).empty? end |
#violations(html) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/activemail/quality/guard.rb', line 40 def violations(html) violations = [] check_size(html, violations) doc = Nokogiri::HTML(html) check_well_formed(doc, violations) check_table_roles(doc, violations) check_img_alts(doc, violations) check_full_document(html, doc, violations) if ::ActiveMail.full_document?(html) violations end |