class EntertainmentOperations
Public Class Methods
cutLowestRatedHalf(objectArray)
click to toggle source
# File lib/entertainment_operations.rb, line 25 def self.cutLowestRatedHalf(objectArray) objectArray = sortByRating(objectArray).reverse objectArray.drop(objectArray.length/2) end
getHighestRated(objectArray)
click to toggle source
# File lib/entertainment_operations.rb, line 15 def self.getHighestRated(objectArray) objectArray = sortByRating(objectArray) puts objectArray.last end
getLowestRated(objectArray)
click to toggle source
# File lib/entertainment_operations.rb, line 20 def self.getLowestRated(objectArray) objectArray = sortByRating(objectArray) puts objectArray.first end
printSortedListByCategory(objectArray, categoryNumber)
click to toggle source
# File lib/entertainment_operations.rb, line 81 def self.printSortedListByCategory(objectArray, categoryNumber) objectArray = sortByCategory(objectArray, categoryNumber) objectArray.each {|obj| puts obj} end
printSortedListByGenre(objectArray)
click to toggle source
# File lib/entertainment_operations.rb, line 64 def self.printSortedListByGenre(objectArray) objectArray = sortByGenre(objectArray) objectArray.each {|obj| puts obj} end
printSortedListByRating(objectArray)
click to toggle source
# File lib/entertainment_operations.rb, line 30 def self.printSortedListByRating(objectArray) objectArray = sortByRating(objectArray) objectArray.each {|obj| puts obj} end
printSortedListByTitle(objectArray)
click to toggle source
# File lib/entertainment_operations.rb, line 47 def self.printSortedListByTitle(objectArray) objectArray = sortByTitle(objectArray) objectArray.each {|obj| puts obj} end
sortByCategory(objectArray, categoryNumber)
click to toggle source
Category operations - objects must have category array
# File lib/entertainment_operations.rb, line 71 def self.sortByCategory(objectArray, categoryNumber) # sorts by category alphabetically unless defined?(objectArray[categoryNumber].category.first) puts "Object must have category array." return end objectArray.sort_by {|m| m.category.first.downcase} end
sortByGenre(objectArray)
click to toggle source
Genre operations - objects must have genre
# File lib/entertainment_operations.rb, line 54 def self.sortByGenre(objectArray) # sorts by genre alphabetically unless defined?(objectArray[0].genre) puts "Object does not have genre." return end objectArray.sort_by {|m| m.genre.downcase} end
sortByRating(objectArray)
click to toggle source
Rating operations - objects must have Rating
# File lib/entertainment_operations.rb, line 5 def self.sortByRating(objectArray) # sorts in ascending order of rating: unless defined?(objectArray[0].rating) puts "Object does not have rating." return end objectArray.sort_by {|m| m.rating} end
sortByTitle(objectArray)
click to toggle source
Title operations - objects must have title
# File lib/entertainment_operations.rb, line 37 def self.sortByTitle(objectArray) # sorts by name alphabetically unless defined?(objectArray[0].title) puts "Object does not have title." return end objectArray.sort_by {|m| m.title.downcase} end