Skip to content

Instantly share code, notes, and snippets.

@gotjosh
Created June 9, 2016 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotjosh/f967e5ce0a57b4b2984a697be831b526 to your computer and use it in GitHub Desktop.
Save gotjosh/f967e5ce0a57b4b2984a697be831b526 to your computer and use it in GitHub Desktop.
class Event < ActiveRecord::Base
enum format: [:standard, :draft, :cube, :pauper, :modern, :board_games, :commander, :free_for_all, :sealed_deck, :two_headed_giant]
validates :title, presence: true
validates :date, presence: true
validates :format, presence: true
validates :price, presence: true
scope :weekly, -> { where(date: Date.today..6.days.from_now).order(date: :asc).limit(6) }
end
class EventsForTheWeek
def initialize(scope = Event.weekly)
@scope = scope
end
def map(&blk)
scope.map(&blk)
end
def each(&blk)
scope.find_each(&blk)
end
private
attr_reader :scope
end
module Hobbyst
module Biz
class SendWeeklyEventsForTelegram
def initialize(user_message, events = EventsForTheWeek.new, service = SendTelegramMessage)
@user_message = user_message
@events = events
@service = service
end
def self.call(user_message)
new(user_message).call
end
def call
presenter = ViewWeeklyEventsForTelegramPresenter.new(events)
service.call(
chat_id,
presenter.to_markdown
)
end
private
def chat_id
user_message.chat.id
end
attr_reader :events, :service, :user_message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment