Searching the Catalogue
Part of the Object Oriented Programming section of Coddy's Ruby journey. Lesson 53 of 57.
Challenge
EasyAdd the SEARCH command. Keep every command from the previous steps working exactly as before.
SEARCH text: the text may contain spaces. Reply with one line per book whose title contains the text, ignoring case, in order of book id:Dune (available)orEmma (borrowed by ada). With no match replyno matches.
The supplied code passes every input line to library.handle(line) and prints each returned reply on its own line. Member names are single lower-case words, book ids are whole numbers, and the input holds only the commands described so far. Any other command replies unknown command.
Your code goes in book.rb, member.rb and library.rb. main.rb holds the supplied input/output code and cannot be edited.
Try it yourself
require_relative 'book'
require_relative 'member'
require_relative 'library'
# Supplied input/output code: keep it as it is
input = []
while (line = gets)
input << line.chomp
end
library = Library.new
input.each do |line|
library.handle(line).each { |reply| puts reply }
end
All lessons in Object Oriented Programming
1Classes and Objects
Working With FilesDefining ClassesInstance VariablesMethods and selfto_s and inspectRecap - Library Card7Polymorphism and Duck Typing
PolymorphismDuck TypingAbstract Methodscase and ClassesRecap - Payment Methods2Accessors and Self
Readers and WritersCustom Settersself in MethodsIdentity and EqualityRecap - Contact List8Special Methods
Equality and hashOperator MethodsIndexing and AppendingCustom CollectionsRecap - Fractions11Project: Library Management
Books and MembersBorrowing Books3Class Methods and Variables
Class MethodsClass Instance VariablesConstantsFactory MethodsRecap - Coupon CodesPractice on your own: Online Ruby compiler