Sha256: 1361e5acf3b5ce30e2235daaabe91061c3e52394f64b59a471fd2e6af7354967

Contents?: true

Size: 488 Bytes

Versions: 10

Compression:

Stored size: 488 Bytes

Contents

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

    attr_accessor :title, :author

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

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

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dev_training_bot-1.2.0 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.1.2 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.1.1 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.1.0 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.0.5 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.0.4 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.0.3 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.0.2 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.0.1 lib/dev_training_bot/models/topic.rb
dev_training_bot-1.0.0 lib/dev_training_bot/models/topic.rb