Sha256: a2cccd1603e35bb5f7989a52e31086d5ba52d8a3c25be03eb269ce15e90cfb04

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module DevTrainingBot
  class TopicService
    OPEN_TOPICS_REGEX = /Open Topics\s+(\*.*\r\n)+/
    TOPIC_ITEM_REGEX  = /(?<=\* ).*(?=\r)/

    def initialize(drive_service)
      @drive_service = drive_service
    end

    def to_poll
      return '' if empty?
      "\"#{topics.first(10).join('" "')}\""
    end

    def content
      @content ||= @drive_service.export_file(ENV['FILE_ID'], 'text/plain', download_dest: StringIO.new)
    end

    ##
    # Returns a list of topics from a string in the following format:
    #
    # Open Topics
    # * David: Browser rendering optimization: how to get silky smooth animations
    # * David: The JS Event Loop: what nightmares are made of
    # * David: RxJS: Observing the death of Promises
    # * David: Intro to vim
    # * Mo: Ansible
    # * Julio: CSI:RMD Reading error reports like a $BOSS
    # * Anthony: SAML
    # * Jimmi: Gang of Four Design Patterns in Ruby (possibly in different parts)
    #
    # @return [string]
    def topics
      @topics ||= import.map { |topic| Topic.parse(topic) }
    end

    def empty?
      topics.empty?
    end

    private

    def import
      list = content.string[OPEN_TOPICS_REGEX].scan(TOPIC_ITEM_REGEX)
      return [] if list.all?(&:empty?)
      list.sort
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dev_training_bot-1.0.5 lib/dev_training_bot/services/topic_service.rb
dev_training_bot-1.0.4 lib/dev_training_bot/services/topic_service.rb
dev_training_bot-1.0.3 lib/dev_training_bot/services/topic_service.rb