Class: Gamefic::Query::Scoped

Inherits:
Base
  • Object
show all
Defined in:
lib/gamefic/query/scoped.rb

Overview

A Scoped query uses a Scope to select entities to filter based on their relationship to the entity performing the query. For example, Scope::Children would filter from an array of the entity’s descendants.

Instance Attribute Summary collapse

Attributes inherited from Base

#ambiguous, #arguments, #narrative

Instance Method Summary collapse

Methods inherited from Base

#accept?, #ambiguous?, #inspect, #name, #query, #select

Constructor Details

#initialize(scope, *arguments, ambiguous: false, name: nil) ⇒ Scoped

Returns a new instance of Scoped.

Parameters:



13
14
15
16
# File 'lib/gamefic/query/scoped.rb', line 13

def initialize scope, *arguments, ambiguous: false, name: nil
  super(*arguments, ambiguous: ambiguous, name: name)
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



10
11
12
# File 'lib/gamefic/query/scoped.rb', line 10

def scope
  @scope
end

Instance Method Details

#precisionObject



22
23
24
# File 'lib/gamefic/query/scoped.rb', line 22

def precision
  @precision ||= @scope.precision + calculate_precision
end

#span(subject) ⇒ Object



18
19
20
# File 'lib/gamefic/query/scoped.rb', line 18

def span(subject)
  @scope.matches(subject)
end