Class: DevTrainingBot::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_training_bot/models/topic.rb

Constant Summary collapse

REGEX =
/(?<author>.*?(?=:))?:?\s*(?<title>.+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, author = 'Unknown') ⇒ Topic

Returns a new instance of Topic.



11
12
13
14
# File 'lib/dev_training_bot/models/topic.rb', line 11

def initialize(title, author = 'Unknown')
  @title = title
  @author = author || 'Unknown'
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



5
6
7
# File 'lib/dev_training_bot/models/topic.rb', line 5

def author
  @author
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/dev_training_bot/models/topic.rb', line 5

def title
  @title
end

Class Method Details

.parse(topic) ⇒ Object



7
8
9
# File 'lib/dev_training_bot/models/topic.rb', line 7

def self.parse(topic)
  topic.match(REGEX) { |matches| new(matches[:title], matches[:author]) }
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/dev_training_bot/models/topic.rb', line 20

def ==(other)
  author == other.author && title == other.title
end

#to_sObject



16
17
18
# File 'lib/dev_training_bot/models/topic.rb', line 16

def to_s
  "#{author}: #{title}"
end