Class: Iriq::Position
- Inherits:
-
Object
- Object
- Iriq::Position
- 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
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#locator ⇒ Object
readonly
Returns the value of attribute locator.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(host:, scope:, locator:) ⇒ Position
constructor
A new instance of Position.
- #path? ⇒ Boolean
- #query? ⇒ Boolean
-
#to_dump ⇒ Object
Serialized form used by JSON / SQLite storage.
- #to_h ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(host:, scope:, locator:) ⇒ Position
Returns a new instance of Position.
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
23 24 25 |
# File 'lib/iriq/position.rb', line 23 def host @host end |
#locator ⇒ Object (readonly)
Returns the value of attribute locator.
23 24 25 |
# File 'lib/iriq/position.rb', line 23 def locator @locator end |
#scope ⇒ Object (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 |
#hash ⇒ Object
52 53 54 |
# File 'lib/iriq/position.rb', line 52 def hash [@host, @scope, @locator].hash end |
#path? ⇒ Boolean
41 |
# File 'lib/iriq/position.rb', line 41 def path?; @scope == :path; end |
#query? ⇒ Boolean
42 |
# File 'lib/iriq/position.rb', line 42 def query?; @scope == :query; end |
#to_dump ⇒ Object
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_h ⇒ Object
56 57 58 |
# File 'lib/iriq/position.rb', line 56 def to_h { host: @host, scope: @scope, locator: @locator } end |
#to_s ⇒ Object Also known as: inspect
60 61 62 |
# File 'lib/iriq/position.rb', line 60 def to_s "Position(#{@host.inspect}, #{@scope}, #{@locator.inspect})" end |