coding_resources 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c39913830fcac65538dd5dc9db5c7c71cedadda72ef93630139d668831202fe
4
+ data.tar.gz: 5e0a10ae910b1ba5f660c690b60f6eeb443794aee4104b38bd2647f38ab8021d
5
+ SHA512:
6
+ metadata.gz: 72dfaa5fc502cbe2014e4a6615ebad0ea995c9bc89e77b51c912fc14d486d20f90bf95089c1cec1b6d482e5bd23bfdd104fc081dc8db50b0ce330eca32fc1957
7
+ data.tar.gz: b4cbef6a6d1c89d9c5a3b8e482ada71e8c22ec7fcb60da0e0fcf46e30bb8f7d069966db7ad59ef9bf4de83dab759766cc8e48f2e83f02febd74b56626ccb1d1c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in coding_resources.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ CodingResources (0.1.0)
5
+ nokogiri (~> 1.8.2)
6
+ require_all (~> 2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ method_source (0.9.0)
13
+ mini_portile2 (2.3.0)
14
+ nokogiri (1.8.2)
15
+ mini_portile2 (~> 2.3.0)
16
+ pry (0.11.3)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.9.0)
19
+ rake (10.5.0)
20
+ require_all (2.0.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ CodingResources!
27
+ bundler (~> 1.16)
28
+ pry (~> 0)
29
+ rake (~> 10.0)
30
+
31
+ BUNDLED WITH
32
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Christopher Jones'
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ 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/Notes.md ADDED
@@ -0,0 +1,15 @@
1
+ The CLI
2
+ 1. Running the CLI should create a call to the Book class to create all books with name, desc_url, and short_desc.
3
+ 2. CLI should be able to call the Book class to cycle through all books, 25 books at a time.
4
+ 3. CLI should be able to create a search call to the Book class and return only the books that match the search.
5
+ 4. CLI should be able to get details of long_desc and book_url for each book selected.
6
+
7
+ The Book class
8
+ 1. The first call the Book class gets should create all books using the Scraper class.
9
+ 2. The Book class should create multiple pages of books based on either all books or searched for books.
10
+ 3. The Book class should pass along the desc_url in order to get additional details for each book object.
11
+ 4. The Book class should be able to take letters and numbers and search for them in each book name.
12
+
13
+ The Scraper Class.
14
+ 1. Should initialy create all books from a hash of each book.
15
+ 2. Should be able to get details on each specific book.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # CodingResources
2
+
3
+ CodingResources pulls data from FreeTechBooks.com and lists the books and descriptions of each book with a link to read the full book. It also allows you to search for a specific book on the site.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'coding_resources'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install coding_resources
20
+
21
+ ## Usage
22
+
23
+ ##After installation run gem by typing "coding_resources" into the terminal, then:
24
+
25
+ Type 1 to list all books.
26
+
27
+ Type 2 to search for a book.
28
+
29
+ Type 3 to exit.
30
+
31
+ ##After listing or searching for a book:
32
+
33
+ Type 1 to get more details on a book.
34
+
35
+ Type 2 to go to the next page of books.
36
+
37
+ Type 3 to go back one page.
38
+
39
+ Type 4 to go to a specific page.
40
+
41
+ Type 5 to search for a new book.
42
+
43
+ Type 6 to exit.
44
+
45
+ ##After getting details on a specific book:
46
+
47
+ Type 1 to go back to the list of books.
48
+
49
+ Type 2 to search for a new book.
50
+
51
+ Type 3 to exit.
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'Scyntre2017'/coding_resources.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coding_resources"
5
+ Bundler.require(:default, :development)
6
+
7
+ CodingResources::CLI.new.run
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ Bundler.require(:default, :development)
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "coding_resources/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "coding_resources"
8
+ spec.version = CodingResources::VERSION
9
+ spec.authors = ["'Christopher Jones'"]
10
+ spec.email = ["'cjones999983@gmail.com'"]
11
+
12
+ spec.summary = "List of books from FreeTechBooks.com"
13
+ spec.description =
14
+ spec.homepage = "https://github.com/Scyntre2017/coding_resources"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($\).reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.executables = ["coding_resources"]
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry", '~> 0'
26
+
27
+ spec.add_runtime_dependency "nokogiri", '~> 1.8.2'
28
+ spec.add_runtime_dependency "require_all", '~> 2'
29
+ end
@@ -0,0 +1,97 @@
1
+ class CodingResources::Books
2
+
3
+ attr_accessor :name, :desc_url, :description, :book_url
4
+
5
+ @@all = []
6
+ @@pages = []
7
+ @@searched_books = []
8
+
9
+ def initialize(book_hash)
10
+ @name = book_hash.values_at(:name).join
11
+ @desc_url = book_hash.values_at(:desc_url).join
12
+ @@all << self unless CodingResources::Books.find_by_name(self.name)
13
+ end
14
+
15
+ def self.create_from_collection(book_array)
16
+ book_array.each { |book| self.new(book) }
17
+ end
18
+
19
+ def self.all
20
+ @@all
21
+ end
22
+
23
+ def self.all_clear
24
+ @@all.clear
25
+ end
26
+
27
+ def self.searched_books
28
+ @@searched_books
29
+ end
30
+
31
+ def self.searched_books_clear
32
+ @@searched_books.clear
33
+ end
34
+
35
+ def self.pages
36
+ @@pages
37
+ end
38
+
39
+ def self.pages=(pages)
40
+ @@pages = pages
41
+ end
42
+
43
+ def self.pages_clear
44
+ @@pages.clear
45
+ end
46
+
47
+ def self.create_pages(books)
48
+ if books == "all_books"
49
+ self.pages_clear
50
+ self.pages = self.all.each_slice(15).to_a
51
+ elsif books == "search"
52
+ self.pages_clear
53
+ self.pages = self.searched_books.each_slice(15).to_a
54
+ end
55
+ end
56
+
57
+ def self.create_all_books
58
+ book_array = CodingResources::Scraper.scrape_all_books
59
+ self.create_from_collection(book_array)
60
+ self.create_pages("all_books")
61
+ end
62
+
63
+ def self.search(name)
64
+ self.searched_books_clear
65
+ self.all.each do |book|
66
+ @@searched_books << book if book.name.downcase.split(":").join.split(",").join.split.include?(name)
67
+ end
68
+ self.create_pages("search")
69
+ end
70
+
71
+ def self.list(page)
72
+ puts ""
73
+ puts "Page #{page + 1}"
74
+ puts ""
75
+ if self.pages[page] == nil
76
+ puts "No reults found."
77
+ else
78
+ self.pages[page].each.with_index(1) do |book, i|
79
+ puts "#{i}. #{book.name}"
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.find_by_name(name)
85
+ self.all.detect { |i| i.name == name }
86
+ end
87
+
88
+ def details
89
+ info = CodingResources::Scraper.scrape_book_details(self.desc_url)
90
+ self.description = info.values_at(:description).join
91
+ self.book_url = info.values_at(:book_url).join
92
+ puts "#{self.description}"
93
+ puts ""
94
+ puts "To download the book please go to this website: #{self.book_url}"
95
+ end
96
+
97
+ end
@@ -0,0 +1,125 @@
1
+ class CodingResources::CLI
2
+
3
+ @@page = 0
4
+
5
+ def run
6
+ menu
7
+ end
8
+
9
+ def menu
10
+ CodingResources::Books.create_all_books
11
+ puts "Welcome to Coding Resources"
12
+ puts "Please select an option"
13
+ puts "1. List all books."
14
+ puts "2. Search for a book."
15
+ puts "3. Exit."
16
+ puts ""
17
+ input = gets.strip.to_i
18
+ if input > 0
19
+ case input
20
+ when 1
21
+ list
22
+ when 2
23
+ search
24
+ when 3
25
+ puts "Have a nice day!"
26
+ exit
27
+ end
28
+ else
29
+ puts "That was an invalid selection."
30
+ menu
31
+ end
32
+ end
33
+
34
+ def list
35
+ if CodingResources::Books.pages.length > 0
36
+ while @@page >= 0 && @@page <= CodingResources::Books.pages.length
37
+ CodingResources::Books.list(@@page)
38
+
39
+ puts ""
40
+
41
+ puts "Please select an option:"
42
+ puts "1. Get more details on a book."
43
+ puts "2. Go to the next page of 15 books."
44
+ puts "3. Go back one page."
45
+ puts "4. Go to a specific page."
46
+ puts "5. Search for a book."
47
+ puts "6. Exit"
48
+ puts ""
49
+
50
+ input = gets.strip.to_i
51
+
52
+ case input
53
+ when 1
54
+ details
55
+ break
56
+ when 2
57
+ @@page += 1
58
+ when 3
59
+ @@page -= 1 unless @@page == 0
60
+ when 4
61
+ puts "Please enter 1-#{CodingResources::Books.pages.length} to go to that specific page."
62
+ i = gets.strip.to_i
63
+ @@page = i - 1
64
+ when 5
65
+ search
66
+ break
67
+ when 6
68
+ exit
69
+ when input > 6 || input < 1
70
+ puts "That was an invalid entry."
71
+ end
72
+ end
73
+ else
74
+ puts ""
75
+ puts "No results found."
76
+ puts "Going back to the main menu"
77
+ puts ""
78
+ menu
79
+ end
80
+ end
81
+
82
+ def search
83
+ puts "Please enter the name or part of the name of the book you are searching for."
84
+ input = gets.strip.downcase
85
+ CodingResources::Books.search(input)
86
+ @@page = 0
87
+ list
88
+ end
89
+
90
+ def details
91
+ puts "Please type the number of the book you would like more information on."
92
+
93
+ puts ""
94
+ input = gets.strip.to_i
95
+ puts ""
96
+
97
+ book = CodingResources::Books.pages[@@page][input - 1]
98
+ book.details
99
+
100
+ i = 0
101
+ while i < 1 || i > 3
102
+ puts ""
103
+ puts "Please select an option:"
104
+ puts "1. Go back to the list of books."
105
+ puts "2. Search for a new book."
106
+ puts "3. Exit"
107
+ puts ""
108
+ i = gets.strip.to_i
109
+ if i > 0
110
+ case i
111
+ when 1
112
+ list
113
+ when 2
114
+ search
115
+ when 3
116
+ puts "Have a nice day!"
117
+ exit
118
+ end
119
+ else
120
+ puts "That was an invalid selection."
121
+ end
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,27 @@
1
+ class CodingResources::Scraper
2
+
3
+ def self.scrape_all_books
4
+ page = 0
5
+ books = []
6
+ while page < 82
7
+ page += 1
8
+ doc = Nokogiri::HTML(open("http://www.freetechbooks.com/topics?page=#{page}"))
9
+ doc.css(".media-body").each do |book|
10
+ name = book.css("p.media-heading").text
11
+ desc_url = book.css("a").first.attribute("href").value
12
+ books << {name: name, desc_url: desc_url}
13
+ end
14
+ end
15
+
16
+ books
17
+ end
18
+
19
+ def self.scrape_book_details(url)
20
+ details = {}
21
+ doc = Nokogiri::HTML(open(url))
22
+ details[:description] = doc.css("blockquote").text
23
+ details[:book_url] = doc.css("#srvata-content a").attribute("href").value
24
+ details
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ module CodingResources
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "coding_resources"
2
+ require "nokogiri"
3
+ require "open-uri"
4
+ require "require_all"
5
+
6
+ require_all "lib"
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coding_resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Christopher Jones'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: require_all
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2'
83
+ description: https://github.com/Scyntre2017/coding_resources
84
+ email:
85
+ - "'cjones999983@gmail.com'"
86
+ executables:
87
+ - coding_resources
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - Notes.md
96
+ - README.md
97
+ - Rakefile
98
+ - bin/coding_resources
99
+ - bin/console
100
+ - bin/setup
101
+ - coding_resources.gemspec
102
+ - lib/coding_resources.rb
103
+ - lib/coding_resources/books.rb
104
+ - lib/coding_resources/cli.rb
105
+ - lib/coding_resources/scraper.rb
106
+ - lib/coding_resources/version.rb
107
+ homepage: https://github.com/Scyntre2017/coding_resources
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: List of books from FreeTechBooks.com
131
+ test_files: []