Class: FansWatch::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/fanswatch/runner.rb

Overview

Executable code for file(s) in bin/ folder

Class Method Summary collapse

Class Method Details

.attachment_output(attachment) ⇒ Object



42
43
44
# File 'lib/fanswatch/runner.rb', line 42

def self.attachment_output(attachment)
  attachment ? attachment.url.to_s : '(none)'
end

.message_output(message) ⇒ Object



38
39
40
# File 'lib/fanswatch/runner.rb', line 38

def self.message_output(message)
  message ? message : '(blank)'
end

.output_info(page) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fanswatch/runner.rb', line 18

def self.output_info(page)
  page_name = page.name
  separator = Array.new(page.name.length) { '-' }.join
  page_info =
    page.feed.postings.first(3).map.with_index do |post, index|
      posting_info(post, index)
    end.join

  [page_name, separator, page_info].join("\n")
end

.posting_info(post, index) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/fanswatch/runner.rb', line 29

def self.posting_info(post, index)
  [
    "#{index + 1}: ",
    message_output(post.message),
    'Attached: ' + attachment_output(post.attachment),
    "\n\n"
  ].join
end

.run!(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fanswatch/runner.rb', line 6

def self.run!(args)
  page_id = args[0] || ENV['FB_PAGE_ID']
  puts page_id
  unless page_id
    puts 'USAGE: fanswatch [page_id]'
    exit(1)
  end
  page = FansWatch::Page.find(id: page_id)

  output_info(page)
end