Class: ProgramR::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/programr/environment.rb

Custom Environment required methods collapse

Instance Method Summary collapse

Constructor Details

#initialize(history) ⇒ Environment

Returns a new instance of Environment.

Parameters:


6
7
8
9
10
# File 'lib/programr/environment.rb', line 6

def initialize history
  @readonly_tags_file = "#{File.dirname(__FILE__)}/../../conf/readOnlyTags.yaml"
  @readonly_tags = YAML::load(File.open(@readonly_tags_file))
  @history = history
end

Instance Method Details

#get(key) ⇒ Object


12
13
14
15
16
17
# File 'lib/programr/environment.rb', line 12

def get key
  return @history.send(key) if key =~ /that$/
  return questions.sample if key == 'question'
  return @readonly_tags[key] if @readonly_tags.key?(key)
  nil
end

#readonly_tags_fileObject


26
27
28
# File 'lib/programr/environment.rb', line 26

def readonly_tags_file
  @readonly_tags_file
end

#readonly_tags_file=(file) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/programr/environment.rb', line 30

def readonly_tags_file= file
  unless File.exist? file
    raise "File #{file} not exist"
  end
  @readonly_tags_file = file
  @readonly_tags = YAML::load(File.open(file))
end

#set(key, value) ⇒ Object


19
20
21
22
# File 'lib/programr/environment.rb', line 19

def set key, value
  @history.topic = value if key == 'topic'
  @readonly_tags[key] = value
end