Class: DevTrainingBot::Topic
- Inherits:
-
Object
- Object
- DevTrainingBot::Topic
- Defined in:
- lib/dev_training_bot/models/topic.rb
Constant Summary collapse
- REGEX =
/(?<author>.*?(?=:))?:?\s*(?<title>.+)/
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(title, author = 'Unknown') ⇒ Topic
constructor
A new instance of Topic.
- #to_s ⇒ Object
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, = 'Unknown') @title = title @author = || 'Unknown' end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
5 6 7 |
# File 'lib/dev_training_bot/models/topic.rb', line 5 def @author end |
#title ⇒ Object
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) == other. && title == other.title end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/dev_training_bot/models/topic.rb', line 16 def to_s "#{}: #{title}" end |