Class: Iriq::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/iriq/position.rb

Overview

A typed slot in a host’s URL structure.

Two observations occupy the same Position when (host, scope, locator) match exactly. Position is the keying type used by Storage for frequency tables and by Cluster for per-slot inference.

host — the EFFECTIVE host per Corpus#host_strategy. Observations of

api.foo.com and app.foo.com under :registrable share the
same Position. The original host stays on the Identifier.

scope — :path or :query. locator — for :path, the typed prefix built up to this slot, e.g.

  "/orgs/{opaque_id}/users" for the integer slot in
  /orgs/abc/users/123. (Variable segments render as their
  hint or display-type, so the prefix groups across observations
  regardless of the specific IDs seen.)
— for :query, the ?key= parameter name.

Position implements value equality and is safe to use as a Hash key.

Constant Summary collapse

SCOPES =
%i[path query].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, scope:, locator:) ⇒ Position

Returns a new instance of Position.

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
# File 'lib/iriq/position.rb', line 33

def initialize(host:, scope:, locator:)
  raise ArgumentError, "scope must be one of #{SCOPES.inspect}" unless SCOPES.include?(scope)

  @host    = host
  @scope   = scope
  @locator = locator
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



23
24
25
# File 'lib/iriq/position.rb', line 23

def host
  @host
end

#locatorObject (readonly)

Returns the value of attribute locator.



23
24
25
# File 'lib/iriq/position.rb', line 23

def locator
  @locator
end

#scopeObject (readonly)

Returns the value of attribute scope.



23
24
25
# File 'lib/iriq/position.rb', line 23

def scope
  @scope
end

Class Method Details

.from_dump(h) ⇒ Object



71
72
73
# File 'lib/iriq/position.rb', line 71

def self.from_dump(h)
  new(host: h["host"], scope: h["scope"].to_sym, locator: h["locator"])
end

.path(host:, prefix:) ⇒ Object



25
26
27
# File 'lib/iriq/position.rb', line 25

def self.path(host:, prefix:)
  new(host: host, scope: :path, locator: prefix)
end

.query(host:, name:) ⇒ Object



29
30
31
# File 'lib/iriq/position.rb', line 29

def self.query(host:, name:)
  new(host: host, scope: :query, locator: name)
end

Instance Method Details

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



44
45
46
47
48
49
# File 'lib/iriq/position.rb', line 44

def ==(other)
  other.is_a?(Position) &&
    other.host == @host &&
    other.scope == @scope &&
    other.locator == @locator
end

#hashObject



52
53
54
# File 'lib/iriq/position.rb', line 52

def hash
  [@host, @scope, @locator].hash
end

#path?Boolean

Returns:

  • (Boolean)


41
# File 'lib/iriq/position.rb', line 41

def path?;  @scope == :path;  end

#query?Boolean

Returns:

  • (Boolean)


42
# File 'lib/iriq/position.rb', line 42

def query?; @scope == :query; end

#to_dumpObject

Serialized form used by JSON / SQLite storage. Scope is emitted as a string for cross-runtime compatibility.



67
68
69
# File 'lib/iriq/position.rb', line 67

def to_dump
  { "host" => @host, "scope" => @scope.to_s, "locator" => @locator }
end

#to_hObject



56
57
58
# File 'lib/iriq/position.rb', line 56

def to_h
  { host: @host, scope: @scope, locator: @locator }
end

#to_sObject Also known as: inspect



60
61
62
# File 'lib/iriq/position.rb', line 60

def to_s
  "Position(#{@host.inspect}, #{@scope}, #{@locator.inspect})"
end