Class: MonoVM::Whois::Availability::Analyzer

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

Overview

Runs a response through the rule chain and returns the first verdict.

The analyzer holds no detection logic of its own — it walks the RuleSet, stops at the first rule that answers, and records what every rule said on the way. That trace is what turns "why does this say available?" from an afternoon of guessing into one call to #explain.

When no rule answers, the result is :unknown. That is the other half of the correctness argument: the default is "I do not know", not "it is free".

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules: nil) ⇒ Analyzer

Returns a new instance of Analyzer.



22
23
24
# File 'lib/monovm/whois/availability/analyzer.rb', line 22

def initialize(rules: nil)
  @rules = rules || RuleSet.default
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



20
21
22
# File 'lib/monovm/whois/availability/analyzer.rb', line 20

def rules
  @rules
end

Instance Method Details

#analyze(response:, tld: nil, definition: nil) ⇒ Verdict

Parameters:

  • (defaults to: nil)
  • (defaults to: nil)

Returns:



30
31
32
33
# File 'lib/monovm/whois/availability/analyzer.rb', line 30

def analyze(response:, tld: nil, definition: nil)
  context = Context.new(response: response, tld: tld, definition: definition)
  run(context)
end

#explain(response:, tld: nil, definition: nil) ⇒ Hash

Analyse and return the verdict together with every rule's outcome, for debugging a surprising classification.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/monovm/whois/availability/analyzer.rb', line 39

def explain(response:, tld: nil, definition: nil)
  context = Context.new(response: response, tld: tld, definition: definition)
  verdict = run(context)

  {
    status: verdict.status,
    decided_by: verdict.rule,
    reason: verdict.reason,
    evidence: verdict.evidence,
    trace: verdict.trace,
    tld: tld,
    response_length: context.length,
    response_preview: context.preview
  }
end