Class: Inprovise::ScriptIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/inprovise/script_index.rb

Overview

Script Index for Inprovise

Author

Martin Corino

License

Distributes under the same license as Ruby

Defined Under Namespace

Classes: MissingScriptError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index_name) ⇒ ScriptIndex

Returns a new instance of ScriptIndex.



9
10
11
12
# File 'lib/inprovise/script_index.rb', line 9

def initialize(index_name)
  @index_name = index_name
  @scripts = {}
end

Instance Attribute Details

#index_nameObject (readonly)

Returns the value of attribute index_name.



7
8
9
# File 'lib/inprovise/script_index.rb', line 7

def index_name
  @index_name
end

Class Method Details

.defaultObject



14
15
16
# File 'lib/inprovise/script_index.rb', line 14

def self.default
  @default ||= new('default')
end

Instance Method Details

#add(scr) ⇒ Object



18
19
20
# File 'lib/inprovise/script_index.rb', line 18

def add(scr)
  @scripts[scr.name] = scr
end

#clear!Object



32
33
34
# File 'lib/inprovise/script_index.rb', line 32

def clear!
  @scripts = {}
end

#get(scr_name) ⇒ Object

Raises:



22
23
24
25
26
# File 'lib/inprovise/script_index.rb', line 22

def get(scr_name)
  scr = @scripts[scr_name]
  raise MissingScriptError.new(index_name, scr_name) if scr.nil?
  scr
end

#scriptsObject



28
29
30
# File 'lib/inprovise/script_index.rb', line 28

def scripts
  @scripts.keys
end