Library_mw 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b25acacc33dd5ec0d8fd9b371a6aa9019efff329
4
+ data.tar.gz: bf5457523387bffd2122910135ab62c210bab7d9
5
+ SHA512:
6
+ metadata.gz: 9c34901ae06be57655760550c8e6937b019f82cee0ba07b2a8d412a4fb0539dc02cc15afb9184251ddb714e4df147a07b991b028758cacab83ee01a26dc67480
7
+ data.tar.gz: e2797a37af84728deb0b0ef67e7ba94e09323cbc0187addf70f7ed47a9eef6f8019eb7e1cac2b04a8fbcc1103e985e9b705b4766d48606b908c2e177007c3e51
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2015 Michael Walsh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ - You may not use this Software in other training contexts.
11
+
12
+ - The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
File without changes
@@ -0,0 +1,15 @@
1
+ manly,1 highwater place,alamo,tom clancy,A12345.111.1
2
+ coogee,2 ifbysea avenue,the tempest,shakespeare,B45678.123.3
3
+ coogee,2 ifbysea avenue,the shock of the new,jack hubbard,C12234.222.4
4
+ manly,1 highwater place,frankly speaking about harry,mike smantd,A43322.124.4
5
+ manly,1 highwater place,johnathon frakes alive,mike cuthbert,A44312.124.4
6
+ manly,1 highwater place,just popped in to see mary,john pettigrew,A94342.124.4
7
+ manly,1 highwater place,how about those nicks,ahmad baker,A84372.124.4
8
+ manly,1 highwater place,creature comforts,m k goodstaff,P44392.124.4
9
+ manly,1 highwater place,catering for the over 50 crowd,john holland,J33432.124.4
10
+ coogee,2 ifbysea avenue,no complaining,carey elwes,U85678.123.3
11
+ coogee,2 ifbysea avenue,shacking up with the in-laws,jack black,E42234.222.4
12
+ coogee,2 ifbysea avenue,how about dinner,Tim foster,B45678.173.3
13
+ coogee,2 ifbysea avenue,did i disturb you?,jess arncliffe,H92234.222.4
14
+ coogee,2 ifbysea avenue,r u ok,peter stormare,D75678.123.3
15
+ coogee,2 ifbysea avenue,mallard season,bill heffernan,Z45334.222.4
@@ -0,0 +1,11 @@
1
+ require 'CSV'
2
+
3
+ module Library
4
+ module LoadLibrary
5
+
6
+ def read_file(filename)
7
+ CSV.read(filename)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/library/library'
4
+ require_relative '../lib/library/book'
5
+ require 'CSV'
6
+
7
+ all_books = CSV.read('.\books.csv')
8
+
9
+ municipality = []
10
+ location = 0
11
+ libraries = []
12
+ all_books.each do |book|
13
+ libraries << book.first(2)
14
+ end
15
+
16
+ libraries.uniq!.each do |libr|
17
+ municipality[location] = Library::Library.new(libr[0], libr[1])
18
+ location += 1
19
+ end
20
+
21
+ municipality.each do |loc|
22
+ puts loc.to_s
23
+ end
24
+
25
+ all_books.each do |book|
26
+ municipality.each do |library|
27
+ if book[0].capitalize == library.name
28
+ library.add_book(Library::Book.new(book[2],book[3], book[4]))
29
+ end
30
+ end
31
+ end
32
+
33
+ municipality.each do |library|
34
+ puts "\nBooks located at #{library.name} are:"
35
+ library.show_books_in_library
36
+ end
37
+
38
+ puts "Book Search. Enter Book Name or ISBN):"
39
+ book_search = gets.chomp
40
+
41
+
42
+ go_to_library = nil
43
+ go_to_book = nil
44
+ puts "\nSearching Libraries......"
45
+ municipality.each do |a_library|
46
+ go_to_book = a_library.find_book(book_search)
47
+ go_to_library = a_library
48
+ if go_to_book != nil
49
+ break
50
+ end
51
+ end
52
+
53
+ if go_to_book != nil
54
+ puts go_to_library.to_s
55
+ puts go_to_book.show_book_details
56
+ else
57
+ puts "Can't find that book. Try elsewhere or come back next month"
58
+ end
59
+
60
+ if go_to_book !=nil
61
+ puts "Do you want to borrow it?"
62
+ answer = gets.chomp
63
+ if answer == 'y'
64
+ go_to_book.checkout
65
+ end
66
+ end
67
+
68
+ municipality.each do |library|
69
+ puts "\nBooks located at #{library.name} are:"
70
+ library.show_books_in_library
71
+ end
@@ -0,0 +1,9 @@
1
+ require 'CSV'
2
+
3
+ libraries = []
4
+ all_books = CSV.read('.\books.csv')
5
+ all_books.each do |book|
6
+ libraries << book.first(2)
7
+ end
8
+
9
+ puts libraries.uniq
@@ -0,0 +1,7 @@
1
+
2
+ (1..10).each do |y|
3
+ x += y
4
+ puts x
5
+ end
6
+
7
+ puts x
@@ -0,0 +1,23 @@
1
+ module Library
2
+ class Book
3
+ attr_reader :name
4
+ attr_reader :status
5
+
6
+ def initialize(name, author, isbn)
7
+ @name = name.split.map(&:capitalize).join(' ')
8
+ @author = author.split.map(&:capitalize).join(' ')
9
+ @isbn = isbn
10
+ @status = true
11
+ end
12
+
13
+ def show_book_details
14
+ have_it = @status ? "available" : "not available"
15
+ "#{@name} (ISBN: #{@isbn}) by #{@author} - (#{have_it})"
16
+ end
17
+
18
+ def checkout
19
+ @status = false
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'book'
2
+
3
+ module Library
4
+ class Library
5
+ attr_reader :name
6
+ attr_reader :books
7
+
8
+ def initialize(name, address)
9
+ @name = name.split.map(&:capitalize).join(' ')
10
+ @address = address.split.map(&:capitalize).join(' ')
11
+ @books =[]
12
+ end
13
+
14
+ def add_book(book)
15
+ @books << book
16
+ end
17
+
18
+ def to_s
19
+ "#{@name} library is located at #{@address}, #{@name}"
20
+ end
21
+
22
+ def find_book(book_title)
23
+ return_book = nil
24
+ @books.each do |book|
25
+ if book.name.upcase == book_title.upcase
26
+ return_book = book
27
+ end
28
+ end
29
+ return return_book
30
+ end
31
+
32
+ def show_books_in_library
33
+ @books.each do |book|
34
+ puts book.show_book_details
35
+ end
36
+ end
37
+
38
+ end #Library
39
+ end #Library
@@ -0,0 +1,30 @@
1
+ require 'library/book'
2
+
3
+ module Library
4
+ describe 'Book' do
5
+ before do
6
+ @alamo = Book.new('alamo','john b. higgins','12345.111.1')
7
+ end
8
+
9
+ describe '#new' do
10
+ it 'creates an object of class Book' do
11
+ expect(@alamo).to be_an_instance_of Book
12
+ end
13
+
14
+ it 'has a capitalized name' do
15
+ expect(@alamo.name).to eq('Alamo')
16
+ end
17
+
18
+ it 'has a status of checked-in' do
19
+ expect(@alamo.status).to be true
20
+ end
21
+ end #new
22
+
23
+ describe '#show_book_details' do
24
+ it 'formats the book output' do
25
+ expect(@alamo.show_book_details).to eq('Alamo (ISBN: 12345.111.1) by John B. Higgins - (available)')
26
+ end
27
+ end
28
+
29
+ end #Book
30
+ end #module
@@ -0,0 +1,27 @@
1
+ require 'library/library'
2
+
3
+ module Library
4
+
5
+ describe 'Library' do
6
+ before do
7
+ @manly = Library.new('manly', '1 Harbourside Place')
8
+ end
9
+
10
+ describe '#new' do
11
+ it 'creates an instance of Library' do
12
+ expect(@manly).to be_an_instance_of Library
13
+ end
14
+
15
+ it 'has a capitalized name' do
16
+ expect(@manly.name).to eq('Manly')
17
+ end
18
+ end #new
19
+
20
+ describe '#to_s' do
21
+ it 'formats the name and address' do
22
+ expect(@manly.to_s).to eq('Manly library is located at 1 Harbourside Place, Manly')
23
+ end
24
+ end
25
+
26
+ end #Library
27
+ end #module
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Library_mw
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Walsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: ''
28
+ email: michael.tom.walsh@gmail.com
29
+ executables:
30
+ - my_library
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README
36
+ - bin/books.csv
37
+ - bin/load_library.rb
38
+ - bin/my_library
39
+ - bin/read_file.rb
40
+ - bin/test.rb
41
+ - lib/library/book.rb
42
+ - lib/library/library.rb
43
+ - spec/library/book_spec.rb
44
+ - spec/library/library_spec.rb
45
+ homepage: https://au.linkedin.com/in/Monkee45
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '1.9'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.2.3
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: simiple library program that loads books and allows a simple search
69
+ test_files:
70
+ - spec/library/book_spec.rb
71
+ - spec/library/library_spec.rb