Class: EntertainmentOperations
- Inherits:
-
Object
- Object
- EntertainmentOperations
- Defined in:
- lib/entertainment_operations.rb
Class Method Summary collapse
- .cutLowestRatedHalf(objectArray) ⇒ Object
- .getHighestRated(objectArray) ⇒ Object
- .getLowestRated(objectArray) ⇒ Object
- .printSortedListByCategory(objectArray, categoryNumber) ⇒ Object
- .printSortedListByGenre(objectArray) ⇒ Object
- .printSortedListByRating(objectArray) ⇒ Object
- .printSortedListByTitle(objectArray) ⇒ Object
-
.sortByCategory(objectArray, categoryNumber) ⇒ Object
Category operations - objects must have category array.
-
.sortByGenre(objectArray) ⇒ Object
Genre operations - objects must have genre.
-
.sortByRating(objectArray) ⇒ Object
Rating operations - objects must have Rating.
-
.sortByTitle(objectArray) ⇒ Object
Title operations - objects must have title.
Class Method Details
.cutLowestRatedHalf(objectArray) ⇒ Object
25 26 27 28 |
# File 'lib/entertainment_operations.rb', line 25 def self.cutLowestRatedHalf(objectArray) objectArray = sortByRating(objectArray).reverse objectArray.drop(objectArray.length/2) end |
.getHighestRated(objectArray) ⇒ Object
15 16 17 18 |
# File 'lib/entertainment_operations.rb', line 15 def self.getHighestRated(objectArray) objectArray = sortByRating(objectArray) puts objectArray.last end |
.getLowestRated(objectArray) ⇒ Object
20 21 22 23 |
# File 'lib/entertainment_operations.rb', line 20 def self.getLowestRated(objectArray) objectArray = sortByRating(objectArray) puts objectArray.first end |
.printSortedListByCategory(objectArray, categoryNumber) ⇒ Object
81 82 83 84 |
# File 'lib/entertainment_operations.rb', line 81 def self.printSortedListByCategory(objectArray, categoryNumber) objectArray = sortByCategory(objectArray, categoryNumber) objectArray.each {|obj| puts obj} end |
.printSortedListByGenre(objectArray) ⇒ Object
64 65 66 67 |
# File 'lib/entertainment_operations.rb', line 64 def self.printSortedListByGenre(objectArray) objectArray = sortByGenre(objectArray) objectArray.each {|obj| puts obj} end |
.printSortedListByRating(objectArray) ⇒ Object
30 31 32 33 |
# File 'lib/entertainment_operations.rb', line 30 def self.printSortedListByRating(objectArray) objectArray = sortByRating(objectArray) objectArray.each {|obj| puts obj} end |
.printSortedListByTitle(objectArray) ⇒ Object
47 48 49 50 |
# File 'lib/entertainment_operations.rb', line 47 def self.printSortedListByTitle(objectArray) objectArray = sortByTitle(objectArray) objectArray.each {|obj| puts obj} end |
.sortByCategory(objectArray, categoryNumber) ⇒ Object
Category operations - objects must have category array
71 72 73 74 75 76 77 78 79 |
# 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) ⇒ Object
Genre operations - objects must have genre
54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
Rating operations - objects must have Rating
5 6 7 8 9 10 11 12 13 |
# File 'lib/entertainment_operations.rb', line 5 def self.sortByRating(objectArray) # sorts in ascending order of rating: unless defined?(objectArray[0].) puts "Object does not have rating." return end objectArray.sort_by {|m| m.} end |
.sortByTitle(objectArray) ⇒ Object
Title operations - objects must have title
37 38 39 40 41 42 43 44 45 |
# 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 |