Class: Org::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/org/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Scope

Returns a new instance of Scope.



5
6
7
8
9
# File 'lib/org/scope.rb', line 5

def initialize(name, options = {})
  @rules = []
  @name, @options = name, options
  @scopes = {}
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/org/scope.rb', line 3

def name
  @name
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/org/scope.rb', line 3

def parent
  @parent
end

#scopesObject

Returns the value of attribute scopes.



3
4
5
# File 'lib/org/scope.rb', line 3

def scopes
  @scopes
end

Instance Method Details

#apply {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Org::Scope)

    the object that the method was called on



21
22
23
# File 'lib/org/scope.rb', line 21

def apply
  yield(self)
end

#inspectObject



31
32
33
# File 'lib/org/scope.rb', line 31

def inspect
  "<Scope #{name}>"
end

#rule(name, regex, options = {}) ⇒ Object



17
18
19
# File 'lib/org/scope.rb', line 17

def rule(name, regex, options = {})
  @rules << Rule.new(name, regex, options)
end

#scope(name, options = {}) {|@scopes[name] = scope| ... } ⇒ Object

Yields:



11
12
13
14
15
# File 'lib/org/scope.rb', line 11

def scope(name, options = {}, &block)
  scope = Scope.new(name, options)
  scope.parent = self
  yield @scopes[name] = scope
end

#step(state) ⇒ Object



25
26
27
28
29
# File 'lib/org/scope.rb', line 25

def step(state)
  @rules.find do |rule|
    rule.match(state)
  end
end