Sha256: c3d8ad8aa05be6b807818c2a3047f5b2fa4f25563c1b2e2d762fbdfc7f1ff588

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module FaceGroups
  # Executable code for file(s) in bin/ folder
  class Runner
    def self.run!(args)
      group_id = args[0] || ENV['FB_GROUP_ID']
      unless group_id
        puts 'USAGE: facegroups [group_id]'
        exit(1)
      end

      group = FaceGroups::Group.find(id: group_id)

      output_info(group)
    end

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

      [name, separator, group_info].join("\n")
    end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facegroups-0.6.2 lib/facegroups/runner.rb