knitpickr 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b3e52581d8bb783e38accd67554d085f091dae175622d62ba2b81ff8cdd7228
4
+ data.tar.gz: 46b84d4c9f0c9cb23f29000796511f7e4ea9ca912cd28e3e6997c61966169107
5
+ SHA512:
6
+ metadata.gz: 3b8906e3d1c7db2970a97d2875544eaa82560c675633cacff0fd15e8e3f73c02c292f43bf307f95afffb96f87eff327ad7484a8889f3890a12ea36cee6527d18
7
+ data.tar.gz: c30334d517480e16c0b361c4b790b52ac9998c553e6fd993afdc3744d09796dbac7e03d4bd1afeecf91f495c5eb0193736161e71eaa959918eb0f37c7aa9036a
data/.gitignore ADDED
@@ -0,0 +1,61 @@
1
+ <<<<<<< HEAD
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+ =======
53
+ /.bundle/
54
+ /.yardoc
55
+ /_yardoc/
56
+ /coverage/
57
+ /doc/
58
+ /pkg/
59
+ /spec/reports/
60
+ /tmp/
61
+ >>>>>>> ccb2412e3aefd095884e826f30cb54e678b3dca8
@@ -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 'sara.mpa13@gmail.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 knitpickr.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ knitpickr-cli-app (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.1)
14
+ mini_portile2 (~> 2.3.0)
15
+ pry (0.11.2)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.4.2)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.16)
38
+ knitpickr-cli-app!
39
+ nokogiri
40
+ pry
41
+ rake (~> 10.0)
42
+ rspec
43
+
44
+ BUNDLED WITH
45
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 'Sara Stanton'
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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Knitpickr
2
+
3
+ This Ruby Gem allows the user to browse yarn sold by Knitpicks (www.knitpicks.com) by yarn weight, yarn fiber content, yarn name, or all sale items.
4
+
5
+ ## Installation
6
+
7
+ $ gem install knitpickr
8
+
9
+ ## Usage
10
+
11
+ Enter the following to get started:
12
+
13
+ $ knitpickr
14
+
15
+ ## Development
16
+
17
+ 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.
18
+
19
+ 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).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sarastanton/knitpickr-cli-app. 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.
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
28
+
29
+ ## Code of Conduct
30
+
31
+ Everyone interacting in the Knitpickr project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'sarampa13-19428'/knitpickr/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "knitpickr"
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
+
11
+ # Pry.start
12
+
13
+ # require "irb"
14
+ # IRB.start(__FILE__)
data/bin/knitpickr ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "knitpickr"
5
+
6
+ Knitpickr::Controller.greeting
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
data/knitpickr.gemspec ADDED
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "knitpickr/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "knitpickr"
8
+ spec.version = Knitpickr::VERSION
9
+ spec.authors = ["'Sara Stanton'"]
10
+ spec.email = ["'sara.mpa13@gmail.com'"]
11
+
12
+ spec.summary = %q{Browse a list of Knitpicks yarn by weight, fiber, name, or sale price.}
13
+ spec.description = %q{Scrape details (such as yarn weight, fiber content, name, and price) from the Knitpicks website (www.knitpicks.com). Users can browse a list of yarn by weight, fiber, name, or sale price.}
14
+ spec.homepage = "https://github.com/sarastanton/knitpickr-cli-app"
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
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = "knitpickr"
31
+ spec.require_paths = ["lib"]
32
+ spec.version = Knitpickr::VERSION
33
+ spec.name = "knitpickr"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec"
38
+ spec.add_development_dependency "nokogiri"
39
+ spec.add_development_dependency "pry"
40
+ end
@@ -0,0 +1,194 @@
1
+ class Knitpickr::Controller
2
+
3
+ def self.greeting
4
+ puts "Hello! Would you like to browse by [1] yarn weight, [2] fiber content, [3] yarn name, or [4] all sale items? Please enter '1', '2', '3', or '4':"
5
+
6
+ input = gets.chomp.to_s
7
+
8
+ until input == "1" || input == "2" || input == "3" || input == "4" || input == "exit"
9
+ puts "Sorry - I don't understand. Please enter '1', '2', '3', '4' or 'exit':"
10
+ input = gets.chomp.to_s
11
+ end
12
+
13
+ case input
14
+ when "1"
15
+ browse_by_weight
16
+ when "2"
17
+ browse_by_fiber
18
+ when "3"
19
+ browse_by_name
20
+ when "4"
21
+ browse_sale
22
+ when "exit"
23
+ puts "Ok, see you later!"
24
+ return nil
25
+ end
26
+
27
+ end
28
+
29
+ def self.browse_by_weight
30
+ puts "Here is a list of all yarn weight options - to learn more, enter the number listed below:"
31
+ Knitpickr::Scraper.all_weights.each_with_index {|x, i| puts "#{i+1}. #{x}"}
32
+ puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'."
33
+
34
+ input = gets.chomp
35
+
36
+ until input.to_i != 0 || input == "exit" || input == "list"
37
+ puts "Sorry - I don't understand. Please enter '1', '2', '3', or 'exit':"
38
+ input = gets.chomp
39
+ end
40
+
41
+ if input == "exit"
42
+ puts "Ok, see you later!"
43
+ return nil
44
+ elsif input == "list"
45
+ self.browse_by_weight
46
+ elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_weights.count
47
+
48
+ index = input.to_i - 1
49
+
50
+ selection = Knitpickr::Yarn.find_by_weight(Knitpickr::Scraper.all_weights[index])
51
+ Knitpickr::Yarn.show_details(selection)
52
+ else
53
+ puts "Hmm, I don't see that number on the list. Let's try this again..."
54
+ self.browse_by_weight
55
+ end
56
+
57
+ puts "Browse again? (Y/N)"
58
+ input = gets.chomp.downcase
59
+
60
+ case input
61
+ when "y"
62
+ self.greeting
63
+ when "n"
64
+ puts "Ok, see you later!"
65
+ return nil
66
+ end
67
+
68
+ end
69
+
70
+ def self.browse_by_fiber
71
+ puts "Here is a list of all yarn fiber content options - to learn more, enter the number listed below:"
72
+ Knitpickr::Scraper.all_fibers.each_with_index {|x, i| puts "#{i+1}. #{x}"}
73
+ puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'."
74
+
75
+ input = gets.chomp
76
+
77
+ until input.to_i != 0 || input == "exit" || input == "list"
78
+ puts "Sorry - I don't understand. Please enter '1', '2', '3', or 'exit':"
79
+ input = gets.chomp
80
+ end
81
+
82
+ if input == "exit"
83
+ puts "Ok, see you later!"
84
+ return nil
85
+ elsif input == "list"
86
+ self.browse_by_fiber
87
+ elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_fibers.count
88
+ index = input.to_i - 1
89
+ selection = Knitpickr::Yarn.find_by_fiber(Knitpickr::Scraper.all_fibers[index])
90
+ Knitpickr::Yarn.show_details(selection)
91
+ else
92
+ puts "Hmm, I don't see that number on the list. Let's try this again..."
93
+ self.browse_by_fiber
94
+ end
95
+
96
+ puts "Browse again? (Y/N)"
97
+ input = gets.chomp.downcase
98
+
99
+ case input
100
+ when "y"
101
+ self.greeting
102
+ when "n"
103
+ puts "Ok, see you later!"
104
+ return nil
105
+ end
106
+
107
+ end
108
+
109
+ def self.browse_by_name
110
+ puts "Here is a list of all yarn names - to learn more, enter the number listed below:"
111
+ Knitpickr::Scraper.all_names.each_with_index {|x, i| puts "#{i+1}. #{x}"}
112
+ puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'."
113
+
114
+ input = gets.chomp
115
+
116
+ until input.to_i != 0 || input == "exit" || input == "list"
117
+ puts "Sorry - I don't understand. Please enter '1', '2', '3', or 'exit':"
118
+ input = gets.chomp
119
+ end
120
+
121
+ if input == "exit"
122
+ puts "Ok, see you later!"
123
+ return nil
124
+ elsif input == "list"
125
+ self.browse_by_name
126
+ elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_names.count
127
+ index = input.to_i - 1
128
+ selection = Knitpickr::Yarn.find_by_name(Knitpickr::Scraper.all_names[index])
129
+ Knitpickr::Yarn.show_details(selection)
130
+ else
131
+ puts "Hmm, I don't see that number on the list. Let's try this again..."
132
+ self.browse_by_name
133
+ end
134
+
135
+ puts "Browse again? (Y/N)"
136
+ input = gets.chomp.downcase
137
+
138
+ case input
139
+ when "y"
140
+ self.greeting
141
+ when "n"
142
+ puts "Ok, see you later!"
143
+ return nil
144
+ end
145
+
146
+ end
147
+
148
+ def self.browse_sale
149
+ puts "Here is a list of all yarn currently on sale - to learn more, enter the number listed below:"
150
+ Knitpickr::Scraper.all_sale.each_with_index {|x, i| puts "#{i+1}. #{x.name} (#{x.price})"}
151
+ puts "Want to learn more? Enter a number from above. You can also enter 'list' to see the list again, or 'exit'."
152
+
153
+ input = gets.chomp
154
+
155
+ until input.to_i != 0 || input == "exit" || input == "list"
156
+ puts "Sorry - I don't understand. Please enter '1', '2', '3', or 'exit':"
157
+ input = gets.chomp
158
+ end
159
+
160
+ if input == "exit"
161
+ puts "Ok, see you later!"
162
+ return nil
163
+ elsif input == "list"
164
+ self.browse_sale
165
+ elsif input.to_i > 0 && input.to_i <= Knitpickr::Scraper.all_sale.count
166
+
167
+ index = input.to_i - 1
168
+
169
+ selection = Knitpickr::Scraper.all_sale[index]
170
+ puts "Yarn name: #{selection.name}"
171
+ puts "Yarn weight: #{selection.weight}"
172
+ puts "Fiber content: #{selection.fiber}"
173
+ puts "Price: #{selection.price}"
174
+ if selection.sale
175
+ puts "On sale!"
176
+ end
177
+ else
178
+ puts "Hmm, I don't see that number on the list. Let's try this again..."
179
+ self.browse_by_sale
180
+ end
181
+
182
+ puts "Browse again? (Y/N)"
183
+ input = gets.chomp.downcase
184
+
185
+ case input
186
+ when "y"
187
+ self.greeting
188
+ when "n"
189
+ puts "Ok, see you later!"
190
+ return nil
191
+ end
192
+ end
193
+
194
+ end
@@ -0,0 +1,66 @@
1
+ require 'pry'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ require_relative "../knitpickr/yarn.rb"
6
+
7
+
8
+ class Knitpickr::Scraper
9
+
10
+ attr_accessor :yarn, :doc
11
+
12
+ @@all_names = []
13
+ @@all_fibers = []
14
+ @@all_weights = []
15
+ @@all_yarns = []
16
+ @@all_sale = []
17
+
18
+ def self.scrape_yarns
19
+ @doc = Nokogiri::HTML(open("http://www.knitpicks.com/yarns/All_Knit_Picks_Yarn__L300198.html?showAll=yes"))
20
+ end
21
+
22
+ def self.make_yarns
23
+ self.scrape_yarns
24
+ all_yarns = @doc.css("div.listItem.book")
25
+
26
+ all_yarns.each do |yarn|
27
+ y = Knitpickr::Yarn.new(yarn.css(".titleSmall").first.attribute("title").value)
28
+ @@all_yarns << y
29
+ y.name = yarn.css(".titleSmall").first.attribute("title").value
30
+ @@all_names << y.name
31
+ y.weight = yarn.css(".yarnWeight")[1].text
32
+ @@all_weights << y.weight
33
+ y.fiber = yarn.css(".yarnWeight").first.text
34
+ @@all_fibers << y.fiber
35
+ y.price = yarn.css(".costSmall").first.text.strip
36
+ if yarn.css(".listItemStatusTags").text == "Sale"
37
+ y.sale = true
38
+ @@all_sale << y
39
+ end
40
+ y
41
+ end
42
+ end
43
+
44
+ def self.all_names
45
+ @@all_names.uniq
46
+ end
47
+
48
+ def self.all_fibers
49
+ @@all_fibers.uniq
50
+ end
51
+
52
+ def self.all_weights
53
+ @@all_weights.uniq
54
+ end
55
+
56
+ def self.all_yarns
57
+ @@all_yarns
58
+ end
59
+
60
+ def self.all_sale
61
+ @@all_sale.uniq
62
+ end
63
+
64
+ make_yarns
65
+
66
+ end
@@ -0,0 +1,3 @@
1
+ module Knitpickr
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'pry'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ class Knitpickr::Yarn
6
+ attr_accessor :name, :weight, :fiber, :price, :sale
7
+
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ @sale = nil
12
+ end
13
+
14
+ def self.find_by_weight(weight)
15
+ Knitpickr::Scraper.all_yarns.select {|yarn| yarn.weight == weight}
16
+ end
17
+
18
+ def self.find_by_name(name)
19
+ Knitpickr::Scraper.all_yarns.select {|yarn| yarn.name == name}
20
+ end
21
+
22
+ def self.find_by_fiber(fiber)
23
+ Knitpickr::Scraper.all_yarns.select {|yarn| yarn.fiber == fiber}
24
+ end
25
+
26
+ def self.find_by_sale(yarn)
27
+ Knitpickr::Scraper.all_yarns.select {|yarn| yarn.sale == true}
28
+ end
29
+
30
+ def self.show_details(selection)
31
+ selection.each do |yarn|
32
+ puts
33
+ puts "Yarn name: #{yarn.name}"
34
+ puts "Yarn weight: #{yarn.weight}"
35
+ puts "Fiber content: #{yarn.fiber}"
36
+ puts "Price: #{yarn.price}"
37
+ if yarn.sale
38
+ puts "On sale!"
39
+ end
40
+ puts "___________________________"
41
+ end
42
+
43
+ end
44
+
45
+ end
data/lib/knitpickr.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'pry'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ require_relative 'knitpickr/controller'
6
+ require_relative 'knitpickr/scraper'
7
+ require_relative 'knitpickr/version'
8
+ require_relative 'knitpickr/yarn'
9
+
10
+ module Knitpickr
11
+ end
data/spec.md ADDED
@@ -0,0 +1,6 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [x] Pull data from an external source
6
+ - [x] Implement both list and detail views
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knitpickr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - "'Sara Stanton'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-08 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: rspec
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: '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: Scrape details (such as yarn weight, fiber content, name, and price)
84
+ from the Knitpicks website (www.knitpicks.com). Users can browse a list of yarn
85
+ by weight, fiber, name, or sale price.
86
+ email:
87
+ - "'sara.mpa13@gmail.com'"
88
+ executables:
89
+ - knitpickr
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/knitpickr
102
+ - bin/setup
103
+ - knitpickr.gemspec
104
+ - lib/knitpickr.rb
105
+ - lib/knitpickr/controller.rb
106
+ - lib/knitpickr/scraper.rb
107
+ - lib/knitpickr/version.rb
108
+ - lib/knitpickr/yarn.rb
109
+ - spec.md
110
+ homepage: https://github.com/sarastanton/knitpickr-cli-app
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.2
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Browse a list of Knitpicks yarn by weight, fiber, name, or sale price.
134
+ test_files: []