Guest User

Untitled

a guest
Sep 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. class Book
  2. def initialize(name:, jacket: :draft)
  3. @name = name
  4. @jacket = jacket
  5. end
  6.  
  7. def name
  8. @name
  9. end
  10.  
  11. def jacket
  12. @jacket
  13. end
  14.  
  15. def transmit
  16. Transmit
  17. end
  18.  
  19. # :haiku:
  20. def send_if_approved
  21. if jacket == :approved
  22. transmit.new([:everyone]).call
  23. else
  24. jacket_destroy
  25. end
  26. end
  27.  
  28. # Read as:
  29. # if jacket approved
  30. # transmit new everyone call
  31. # else jacket destroy
  32.  
  33. # :haiku:
  34. def jacket_destroy
  35. jacket == :destroyed
  36. puts "Destroyed #{Time.now}"
  37. end
  38.  
  39. # Read as:
  40. # def jacket destroy
  41. # jacket equals destroyed
  42. # puts destroyed time now
  43.  
  44. end
  45.  
  46. class Transmit
  47. def initialize(recipients)
  48. @recipients = recipients
  49. end
  50.  
  51. def recipients
  52. @recipients
  53. end
  54.  
  55. def call
  56. send_the_jacket
  57. Log.new("Transmitted to #{@recipients.join(', ')} #{Time.now}")
  58. end
  59.  
  60. private
  61.  
  62. # :haiku:
  63. def send_the_jacket
  64. # TODO: need to write the code
  65. # 'twas ever thus
  66. end
  67.  
  68. # Read as:
  69. # def send the jacket
  70. # to do: need to write the code
  71. # hash twas ever thus
  72.  
  73. end
  74.  
  75. class Log
  76. def initialize(data)
  77. @log = data
  78. puts @log
  79. end
  80. end
  81.  
  82. # :iambic_pentameter_sonnet:
  83. def send_the_jacket_to_the_shops(my_books)
  84. my_books.select { |book| book.jacket == :approved }.each do |book|
  85. book.transmit.new(
  86. # the aggregators
  87. [:nielsen, :bowker]).call
  88. puts "#{book.name} sent to aggregators all"
  89. book.transmit.new([:al_saqi, :kew, :five_leaves]).call
  90. puts "#{book.name} sent to some indies"
  91. book.transmit.new([:nbni]).call
  92. puts "Warehouse has got #{book.name}, one and all"
  93. book.transmit.new([:gardners, :bertrams])
  94. puts "Wholesalers have #{book.name} in the can"
  95. book.transmit.new([:ebsco] && [:jstore])
  96. puts "Academics have #{book.name} for sure."
  97. puts "Every bookstore all throughout the land " \
  98. "has #{book.name}'s jacket in their very hands"
  99. end
  100. end
  101.  
  102. # Read as:
  103. #
  104. # Def send the jacket to the shops, my books
  105. # My books, select book book jacket approved,
  106. # Each do, book block, book dot transmit dot new.
  107. # (The aggregators) Nielsen, Bowker, call
  108. # Puts book name sent to aggregators all
  109. # Book transmit new Al Saqi, Kew, Five Leaves,
  110. # dot call /
  111. # puts Book name sent to some indies,
  112. # Book transmit new NBNI dot call
  113. # puts "Warehouse has got book name, one and all"
  114. # book dot transmit dot Gardners, Bertrams,
  115. # puts "Wholesalers have book name in the can"
  116. # Book transmit new EBSCO and and JSTOR
  117. # puts "Academics have book name for sure."
  118. # puts "Every bookstore, all throughout the land"
  119. # "has book name's jacket in their very hands"
  120. # (end end)
  121.  
  122. my_books = []
  123. my_books << Book.new(name: "Persuasion", jacket: :approved)
  124. my_books << Book.new(name: "Lolita")
  125. my_books << Book.new(name: "Possession")
  126. my_books << Book.new(name: "Beowolf", jacket: :approved)
  127.  
  128. send_the_jacket_to_the_shops(my_books)
  129. my_books.each { |book| book.send_if_approved }
Add Comment
Please, Sign In to add comment