catpedia 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad00c038e808506725c967f08bb6792e079708f749d0df573a50a4b3027f3ca9
4
+ data.tar.gz: d349129885ba6b502657d1961cab3174df3b3bc767446e7a4cfb991e88df8398
5
+ SHA512:
6
+ metadata.gz: b42cd6a97fefe5f349a9278672f72804d40508e5ee989b8460915e8e12683f2128097f615f0020bb28969b83b513671a32d11ddc42aebd45c0b71f877615d54a
7
+ data.tar.gz: 747935c616335ffc15678b0a9162ab7b2b40c7c21d78f920636b9bf11940a15aa2ed37bf85381a552d2c27748d5c8845c16481c07d5020aa5083b105257b68ed
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at werewaswas@live.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 catpedia.gemspec
6
+ gemspec
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ catpedia (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.0)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.4)
14
+ mini_portile2 (~> 2.3.0)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (12.3.1)
19
+ rspec (3.8.0)
20
+ rspec-core (~> 3.8.0)
21
+ rspec-expectations (~> 3.8.0)
22
+ rspec-mocks (~> 3.8.0)
23
+ rspec-core (3.8.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-expectations (3.8.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-mocks (3.8.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-support (3.8.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.16)
38
+ catpedia!
39
+ nokogiri
40
+ pry
41
+ rake (~> 12.3.1)
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 1.16.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 kev112
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.
@@ -0,0 +1,27 @@
1
+ # Catpedia CLI
2
+
3
+ This is a CLI application that scrapes a website and displays a list of cat breeds. Users can see more information regarding each cat.
4
+
5
+ ## Installation
6
+
7
+ Simply clone the repo or download and unzip the files to any folder on your computer.
8
+
9
+ ## Usage
10
+
11
+ To start the program, navigate to the bin folder and run
12
+
13
+ $ ruby catpedia
14
+
15
+ The program will list selection options. Simply type in the number of the menu item (for example, the cat you want to learn more about) to display more information.
16
+
17
+ ## Contributing
18
+
19
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/catpedia. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
20
+
21
+ ## License
22
+
23
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
24
+
25
+ ## Code of Conduct
26
+
27
+ Everyone interacting in the Catpedia project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/catpedia/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin ruby
2
+
3
+ require_relative '../lib/catpedia'
4
+
5
+ Catpedia::CLI.new.start
6
+
7
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "catpedia"
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__)
@@ -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,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "catpedia/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "catpedia"
8
+ spec.version = Catpedia::VERSION
9
+ spec.authors = ["kev112"]
10
+ spec.email = ["werewaswas@live.com"]
11
+
12
+ spec.summary = %q{Catpedia CLI gem}
13
+ spec.description = %q{This ruby gem CLI is a CLI application that scrapes a website and displays a list of cat breeds. Users can see more information regarding each cat.}
14
+ spec.homepage = "https://github.com/kev112/catpedia"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "bin"
32
+ spec.executables << 'catpedia'
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 12.3.1"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "nokogiri", ">= 0"
39
+ spec.add_development_dependency "pry", ">= 0"
40
+ end
@@ -0,0 +1,7 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require_relative '../lib/catpedia/scraper'
6
+ require_relative '../lib/catpedia/cat'
7
+ require_relative '../lib/catpedia/cli'
@@ -0,0 +1,7 @@
1
+
2
+
3
+ module Catpedia
4
+ # Your code goes here...
5
+ end
6
+
7
+ require_relative '../config/environment'
@@ -0,0 +1,18 @@
1
+ class Catpedia::Cat
2
+
3
+ attr_accessor :name, :summary, :history, :personality, :health , :grooming
4
+
5
+ @@all = []
6
+
7
+ def initialize(details)
8
+ @@all << self
9
+ details.each do |key, value| #for each details hash, create keys and values in the instance of Cat
10
+ self.send("#{key}=", value)
11
+ end
12
+ end
13
+
14
+ def self.all
15
+ @@all
16
+ end
17
+
18
+ end
@@ -0,0 +1,85 @@
1
+ class Catpedia::CLI
2
+
3
+ def start
4
+ puts "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
5
+ puts 'Welcome to Catpedia. Please wait a few seconds for the program to load...'
6
+ puts "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
7
+ Catpedia::Scraper.scrape_cats
8
+ list_ranges
9
+ end
10
+
11
+ def list_ranges #puts ranges of cats for user to select
12
+ puts ""
13
+ puts 'Which range of cat breeds would you like to browse? Enter a number:'
14
+ puts ""
15
+ puts "1. '#{Catpedia::Cat.all[0].name}' through '#{Catpedia::Cat.all[9].name}'"
16
+ puts "2. '#{Catpedia::Cat.all[10].name}' through '#{Catpedia::Cat.all[19].name}'"
17
+ puts "3. '#{Catpedia::Cat.all[20].name}' through '#{Catpedia::Cat.all[29].name}'"
18
+ puts "4. '#{Catpedia::Cat.all[30].name}' through '#{Catpedia::Cat.all[39].name}'"
19
+ puts "5. '#{Catpedia::Cat.all[40].name}' through '#{Catpedia::Cat.all.last.name}'"
20
+
21
+ input = gets.strip #gets the user selection and lists cats
22
+ if input == '1'
23
+ list_cats_in_range(0,10)
24
+ elsif input == '2'
25
+ list_cats_in_range(10,10)
26
+ elsif input == '3'
27
+ list_cats_in_range(20,10)
28
+ elsif input == '4'
29
+ list_cats_in_range(30,10)
30
+ elsif input == '5'
31
+ list_cats_in_range(40,10)
32
+ end
33
+ end
34
+
35
+ def list_cats_in_range(a,b)
36
+ puts ""
37
+ puts 'Please select a cat breed:'
38
+ puts ""
39
+ cats = Catpedia::Cat.all[a,b]
40
+ cats.each.with_index do |cat, index|
41
+ puts "#{index + 1}. #{cat.name}" #puts the individual cat breeds for a given range within all cats
42
+ end
43
+
44
+ input = gets.strip #user selects a single cat
45
+ index = input.to_i - 1
46
+ cat = cats[index] #the cat instance from the range of cats array
47
+ list_details(cat)
48
+ end
49
+
50
+ def list_details(cat) #shows detail for specific cat
51
+ puts "\n\rWhat would you like to know more about the #{cat.name}?"
52
+ puts ""
53
+ puts "1. Summary"
54
+ puts "2. History"
55
+ puts "3. Personality"
56
+ puts "4. Health"
57
+ puts "5. Grooming"
58
+ puts "...or 's' to start over, 'q' to quit"
59
+
60
+ input = gets.strip
61
+ case input
62
+ when '1'
63
+ puts "\n\r--------SUMMARY--------\n\r"
64
+ puts "#{cat.summary}"
65
+ when '2'
66
+ puts "\n\r--------HISTORY--------\n\r"
67
+ puts "#{cat.history}"
68
+ when '3'
69
+ puts "\n\r--------PERSONALITY--------\n\r"
70
+ puts "#{cat.personality}"
71
+ when '4'
72
+ puts "\n\r--------HEALTH--------\n\r"
73
+ puts "#{cat.health}"
74
+ when '5'
75
+ puts "\n\r--------GROOMING--------\n\r"
76
+ puts "#{cat.grooming}"
77
+ when 's'
78
+ return list_ranges #go back to start of program
79
+ when 'q'
80
+ exit
81
+ end
82
+
83
+ list_details(cat)
84
+ end
85
+ end
@@ -0,0 +1,28 @@
1
+ class Catpedia::Scraper
2
+
3
+ URL = "http://www.vetstreet.com/cats/breeds"
4
+
5
+ def self.scrape_cats #return array of all cat objects, each with detailed attributes
6
+ cat_urls = Nokogiri::HTML(open(URL)).css("#hub-breed-list-container ul li a")
7
+ cat_urls.each do |e|
8
+ url = "http://www.vetstreet.com/" + e.attr('href')
9
+ cat_details_hash = scrape_cat_details(url)
10
+ Catpedia::Cat.new(cat_details_hash)
11
+ end
12
+ Catpedia::Cat.all
13
+ end
14
+
15
+ def self.scrape_cat_details(url) #return hash of details for a single cat
16
+ cat = {}
17
+ page = Nokogiri::HTML(open(url))
18
+ cat[:name] = page.css(".breed-detail h1").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
19
+ cat[:summary] = page.css("#breed-detail p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
20
+ cat[:history] = page.css("#history .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
21
+ cat[:personality] = page.css("#personality .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
22
+ cat[:health] = page.css("#health .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
23
+ cat[:grooming] = page.css("#grooming .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
24
+ cat
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,3 @@
1
+ module Catpedia
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catpedia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - kev112
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-18 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: 12.3.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This ruby gem CLI is a CLI application that scrapes a website and displays
84
+ a list of cat breeds. Users can see more information regarding each cat.
85
+ email:
86
+ - werewaswas@live.com
87
+ executables:
88
+ - catpedia
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/catpedia
102
+ - bin/console
103
+ - bin/setup
104
+ - catpedia.gemspec
105
+ - config/environment.rb
106
+ - lib/catpedia.rb
107
+ - lib/catpedia/cat.rb
108
+ - lib/catpedia/cli.rb
109
+ - lib/catpedia/scraper.rb
110
+ - lib/catpedia/version.rb
111
+ homepage: https://github.com/kev112/catpedia
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.7.6
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Catpedia CLI gem
135
+ test_files: []