Last active
September 21, 2018 13:47
-
-
Save EmmaB/3f5866ab696dbcabe07a8f36613b843c to your computer and use it in GitHub Desktop.
Code is poetry
This file contains 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 Book | |
def initialize(name:, jacket: :draft) | |
@name = name | |
@jacket = jacket | |
end | |
def name | |
@name | |
end | |
def jacket | |
@jacket | |
end | |
def transmit | |
Transmit | |
end | |
# :haiku: | |
def send_if_approved | |
if jacket == :approved | |
transmit.new([:everyone]).call | |
else | |
jacket_destroy | |
end | |
end | |
# Read as: | |
# if jacket approved | |
# transmit new everyone call | |
# else jacket destroy | |
# :haiku: | |
def jacket_destroy | |
jacket == :destroyed | |
puts "Destroyed #{Time.now}" | |
end | |
# Read as: | |
# def jacket destroy | |
# jacket equals destroyed | |
# puts destroyed time now | |
end | |
class Transmit | |
def initialize(recipients) | |
@recipients = recipients | |
end | |
def recipients | |
@recipients | |
end | |
def call | |
send_the_jacket | |
Log.new("Transmitted to #{@recipients.join(', ')} #{Time.now}") | |
end | |
private | |
# :haiku: | |
def send_the_jacket | |
# TODO: need to write the code | |
# 'twas ever thus | |
end | |
# Read as: | |
# def send the jacket | |
# to do: need to write the code | |
# hash twas ever thus | |
end | |
class Log | |
def initialize(data) | |
@log = data | |
puts @log | |
end | |
end | |
# :iambic_pentameter_sonnet: | |
def send_the_jacket_to_the_shops(my_books) | |
my_books.select { |book| book.jacket == :approved }.each do |book| | |
book.transmit.new( | |
# the aggregators | |
[:nielsen, :bowker]).call | |
puts "#{book.name} sent to aggregators all" | |
book.transmit.new([:al_saqi, :kew, :five_leaves]).call | |
puts "#{book.name} sent to some indies" | |
book.transmit.new([:nbni]).call | |
puts "Warehouse has got #{book.name}, one and all" | |
book.transmit.new([:gardners, :bertrams]) | |
puts "Wholesalers have #{book.name} in the can" | |
book.transmit.new([:ebsco] && [:jstore]) | |
puts "Academics have #{book.name} for sure." | |
puts "Every bookstore all throughout the land " \ | |
"has #{book.name}'s jacket in their very hands" | |
end | |
end | |
# Read as: | |
# | |
# Def send the jacket to the shops, my books | |
# My books, select book book jacket approved, | |
# Each do, book block, book dot transmit dot new. | |
# (The aggregators) Nielsen, Bowker, call | |
# Puts book name sent to aggregators all | |
# Book transmit new Al Saqi, Kew, Five Leaves, | |
# dot call / | |
# puts Book name sent to some indies, | |
# Book transmit new NBNI dot call | |
# puts "Warehouse has got book name, one and all" | |
# book dot transmit dot Gardners, Bertrams, | |
# puts "Wholesalers have book name in the can" | |
# Book transmit new EBSCO and and JSTOR | |
# puts "Academics have book name for sure." | |
# puts "Every bookstore, all throughout the land" | |
# "has book name's jacket in their very hands" | |
# (end end) | |
my_books = [] | |
my_books << Book.new(name: "Persuasion", jacket: :approved) | |
my_books << Book.new(name: "Lolita") | |
my_books << Book.new(name: "Possession") | |
my_books << Book.new(name: "Beowolf", jacket: :approved) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open up IRB (which stands for Interactive Ruby):
irb
, then pressenter
.irb
and pressenter
.irb
window.Then type in the following and press enter:
send_the_jacket_to_the_shops(my_books)
Then type in the following and press enter:
my_books.each { |book| book.send_if_approved }