Class: EntertainmentOperations

Inherits:
Object
  • Object
show all
Defined in:
lib/entertainment_operations.rb

Class Method Summary collapse

Class Method Details

.getHighestRated(hashArray) ⇒ Object



25
26
27
28
# File 'lib/entertainment_operations.rb', line 25

def self.getHighestRated(hashArray)
  hashArray = sortByRating(hashArray)
  return hashArray.first
end

.getLowestRated(hashArray) ⇒ Object



30
31
32
33
# File 'lib/entertainment_operations.rb', line 30

def self.getLowestRated(hashArray)
  hashArray = sortByRating(hashArray)
  return hashArray.last
end

.sortByRating(hashArray) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/entertainment_operations.rb', line 2

def self.sortByRating(hashArray)
  # sorts in ascending order of rating:
  hashArray.sort_by! do |item|
    if item[:rating].nil?
      return -1
    else
      item[:rating]
    end
  end
  return hashArray.reverse
end

.sortByTitle(hashArray) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/entertainment_operations.rb', line 14

def self.sortByTitle(hashArray)
  # sorts by name alphabetically
  hashArray.sort_by do |item|
    if item[:name].nil?
      'zzzzzzzzzzzzzzzzzz'
    else
      item[:name].downcase
    end
  end
end