Created
June 9, 2016 22:10
-
-
Save gotjosh/f967e5ce0a57b4b2984a697be831b526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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