Class: DevTrainingBot::TopicService

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_training_bot/services/topic_service.rb

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(drive_service) ⇒ TopicService

Returns a new instance of TopicService.



6
7
8
# File 'lib/dev_training_bot/services/topic_service.rb', line 6

def initialize(drive_service)
  @drive_service = drive_service
end

Instance Method Details

#contentObject



15
16
17
# File 'lib/dev_training_bot/services/topic_service.rb', line 15

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

#empty?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/dev_training_bot/services/topic_service.rb', line 37

def empty?
  topics.empty?
end

#to_poll(exclude: []) ⇒ Object



10
11
12
13
# File 'lib/dev_training_bot/services/topic_service.rb', line 10

def to_poll(exclude: [])
  return '' if empty?
  "\"#{topics.reject { |topic| topic.author.in?(exclude) }.first(10).join('" "')}\""
end

#topicsstring

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)

Returns:

  • (string)


33
34
35
# File 'lib/dev_training_bot/services/topic_service.rb', line 33

def topics
  @topics ||= import.map { |topic| Topic.parse(topic) }
end