Class: MonoVM::Whois::Availability::Verdict

Inherits:
Object
  • Object
show all
Defined in:
lib/monovm/whois/availability/verdict.rb

Overview

The outcome of analysing one response.

This is the central design decision. With a boolean-only isAvailable(), "this domain is registered" and "the server would not tell me" collapse into the same false — and, worse, a response that carries no verdict at all falls through the detector's heuristics and comes back true. A rate-limited registry then reports every registered domain as free to register.

Here #status has four values and :unknown is a real answer that is never promoted to :available. #rule and #trace record why, which is what makes a surprising classification debuggable.

Constant Summary collapse

STATUSES =
%i[available registered premium unknown].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, rule: nil, reason: nil, evidence: nil, trace: nil) ⇒ Verdict

Returns a new instance of Verdict.

Parameters:

  • status (Symbol)

    one of STATUSES

  • rule (String, nil) (defaults to: nil)

    name of the rule that decided it

  • reason (String, nil) (defaults to: nil)

    human-readable justification

  • evidence (String, nil) (defaults to: nil)

    the matched text, trimmed for display

  • trace (Array<Hash>, nil) (defaults to: nil)

    every rule consulted, in order

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/monovm/whois/availability/verdict.rb', line 36

def initialize(status:, rule: nil, reason: nil, evidence: nil, trace: nil)
  raise ArgumentError, "unknown verdict status #{status.inspect}" unless STATUSES.include?(status)

  @status = status
  @rule = rule
  @reason = reason
  @evidence = evidence
  @trace = (trace || []).freeze
  freeze
end

Instance Attribute Details

#evidenceObject (readonly)

Returns the value of attribute evidence.



21
22
23
# File 'lib/monovm/whois/availability/verdict.rb', line 21

def evidence
  @evidence
end

#reasonObject (readonly)

Returns the value of attribute reason.



21
22
23
# File 'lib/monovm/whois/availability/verdict.rb', line 21

def reason
  @reason
end

#ruleObject (readonly)

Returns the value of attribute rule.



21
22
23
# File 'lib/monovm/whois/availability/verdict.rb', line 21

def rule
  @rule
end

#statusObject (readonly)

Returns the value of attribute status.



21
22
23
# File 'lib/monovm/whois/availability/verdict.rb', line 21

def status
  @status
end

#traceObject (readonly)

Returns the value of attribute trace.



21
22
23
# File 'lib/monovm/whois/availability/verdict.rb', line 21

def trace
  @trace
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



85
86
87
# File 'lib/monovm/whois/availability/verdict.rb', line 85

def ==(other)
  other.is_a?(Verdict) && other.status == status && other.rule == rule
end

#available?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/monovm/whois/availability/verdict.rb', line 47

def available?
  status == :available
end

#conclusive?Boolean

True when the verdict says something actionable about the domain.

Returns:

  • (Boolean)


66
67
68
# File 'lib/monovm/whois/availability/verdict.rb', line 66

def conclusive?
  !unknown?
end

#hashObject



90
91
92
# File 'lib/monovm/whois/availability/verdict.rb', line 90

def hash
  [self.class, status, rule].hash
end

#inspectObject



94
95
96
# File 'lib/monovm/whois/availability/verdict.rb', line 94

def inspect
  "#<#{self.class.name} #{status}#{" by #{rule}" if rule}>"
end

#premium?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/monovm/whois/availability/verdict.rb', line 55

def premium?
  status == :premium
end

#registered?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/monovm/whois/availability/verdict.rb', line 51

def registered?
  status == :registered
end

#to_hObject



76
77
78
79
80
81
82
83
# File 'lib/monovm/whois/availability/verdict.rb', line 76

def to_h
  {
    status: status,
    rule: rule,
    reason: reason,
    evidence: evidence
  }
end

#unknown?Boolean

True when no rule could reach a conclusion, or when the server refused to answer. Callers must treat this as "ask again later", never as free.

Returns:

  • (Boolean)


61
62
63
# File 'lib/monovm/whois/availability/verdict.rb', line 61

def unknown?
  status == :unknown
end

#with_trace(trace) ⇒ Object

Return a copy carrying trace. Rules build verdicts without knowing the trace; the analyzer attaches it once the chain finishes.



72
73
74
# File 'lib/monovm/whois/availability/verdict.rb', line 72

def with_trace(trace)
  self.class.new(status: status, rule: rule, reason: reason, evidence: evidence, trace: trace)
end