Class: Tjplurk::Robot::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/tjplurk/robot/topic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ Topic

Returns a new instance of Topic.



18
19
20
# File 'lib/tjplurk/robot/topic.rb', line 18

def initialize(**params)
  params.each{|key, value| send("#{key}=", value)}
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/tjplurk/robot/topic.rb', line 7

def name
  @name
end

#patternObject

Returns the value of attribute pattern.



7
8
9
# File 'lib/tjplurk/robot/topic.rb', line 7

def pattern
  @pattern
end

#responsesObject

Returns the value of attribute responses.



7
8
9
# File 'lib/tjplurk/robot/topic.rb', line 7

def responses
  @responses
end

Class Method Details

.load(yaml) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/tjplurk/robot/topic.rb', line 9

def load yaml
  YAML.load(yaml).map do |attributes|
    topic = self.new name: attributes['name'], pattern: attributes['pattern']
    topic.responses = attributes['responses'].map{|res| Response.new(topic: topic, content: res)}
    topic
  end
end