Class: UqLibraries::Library

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(library_hash) ⇒ Library

Returns a new instance of Library.



5
6
7
8
9
# File 'lib/uq_libraries/library.rb', line 5

def initialize(library_hash)
    library_hash.each {|attribute, value| self.send("#{attribute}=", value)}
    add_details
    @@all << self
end

Instance Attribute Details

#detailsObject

Returns the value of attribute details.



2
3
4
# File 'lib/uq_libraries/library.rb', line 2

def details
  @details
end

#library_urlObject

Returns the value of attribute library_url.



2
3
4
# File 'lib/uq_libraries/library.rb', line 2

def library_url
  @library_url
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/uq_libraries/library.rb', line 2

def name
  @name
end

#total_availableObject

Returns the value of attribute total_available.



2
3
4
# File 'lib/uq_libraries/library.rb', line 2

def total_available
  @total_available
end

#total_out_of_availableObject

Returns the value of attribute total_out_of_available.



2
3
4
# File 'lib/uq_libraries/library.rb', line 2

def total_out_of_available
  @total_out_of_available
end

Class Method Details

.allObject

Getter method for @@all array. Returns all Library instances



15
16
17
# File 'lib/uq_libraries/library.rb', line 15

def self.all # Getter method for @@all array. Returns all Library instances
    @@all
end

.create_from_collection(libraries_array) ⇒ Object

Creates library instance from an array of hashes returned by Scraper#scrape_main_page



11
12
13
# File 'lib/uq_libraries/library.rb', line 11

def self.create_from_collection(libraries_array) # Creates library instance from an array of hashes returned by Scraper#scrape_main_page
    libraries_array.each {|i| self.new(i)}
end

Instance Method Details

#add_detailsObject

Sets library.details equal to an array of hashes containing different details for each level of the library



19
20
21
# File 'lib/uq_libraries/library.rb', line 19

def add_details # Sets library.details equal to an array of hashes containing different details for each level of the library
    @details = UqLibraries::LibraryDetails.create_from_collection(UqLibraries::Scraper.scrape_details_page(@library_url))
end