knitting_patterns 0.1.0
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 +7 -0
- data/bin/knitting_patterns +5 -0
- data/lib/knitting_patterns.rb +11 -0
- data/lib/knitting_patterns/cli.rb +93 -0
- data/lib/knitting_patterns/pattern.rb +12 -0
- data/lib/knitting_patterns/scraper.rb +27 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4089d84699a3f630eefd22830a344e4470c243192a985f4556b082591624e290
|
4
|
+
data.tar.gz: f744675266dfcfdefcff2c5d7a255763e7611434c53d1d2bb6177dde851bfa9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf280891c31abb6031e05e52b499098f09816d611f24e312961be28ef07227032eaeb496627e2d98f1b3609932467f72a670176d2f40c786e401a27de64b89c6
|
7
|
+
data.tar.gz: c31ea9943a488fa033612201dc77d24fad560178c50506e23925015c0bc01b1a63e995f32573c3b5e163ef18b5337c9468959c4b161bca7f066eff2e38ec9068
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
|
6
|
+
module KnittingPatterns
|
7
|
+
require_relative './knitting_patterns/version'
|
8
|
+
require_relative './knitting_patterns/scraper'
|
9
|
+
require_relative './knitting_patterns/pattern'
|
10
|
+
require_relative './knitting_patterns/cli'
|
11
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class KnittingPatterns::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
puts "Hey fellow knitter!"
|
5
|
+
puts "Here are the categories of the free knitting patterns from Purl Soho:"
|
6
|
+
puts "___________________________________________________________________________________________"
|
7
|
+
list_categories
|
8
|
+
menu
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_categories
|
12
|
+
puts ""
|
13
|
+
@categories = KnittingPatterns::Scraper.new.scrape_knit_categories
|
14
|
+
@categories.each.with_index(1) {|category, index| puts "#{index}. #{category}"}
|
15
|
+
puts "___________________________________________________________________________________________"
|
16
|
+
end
|
17
|
+
|
18
|
+
def list_category_patterns
|
19
|
+
puts "___________________________________________________________________________________________"
|
20
|
+
puts ""
|
21
|
+
KnittingPatterns::Scraper.new.scrape_category_patterns(@input)
|
22
|
+
KnittingPatterns::Pattern.all.each_with_index do |pattern, index|
|
23
|
+
puts "#{index+1}. #{pattern.title}"
|
24
|
+
end
|
25
|
+
puts "___________________________________________________________________________________________"
|
26
|
+
end
|
27
|
+
|
28
|
+
def menu
|
29
|
+
input = nil
|
30
|
+
while input != "exit"
|
31
|
+
puts ""
|
32
|
+
puts "To see all the patterns in a category, enter the corresponding number."
|
33
|
+
puts "Type 'list' to see them all again or 'exit' at anytime to leave."
|
34
|
+
puts "___________________________________________________________________________________________"
|
35
|
+
input = gets.strip.downcase
|
36
|
+
|
37
|
+
if input.to_i == 7
|
38
|
+
@input = "toys-hobbies"
|
39
|
+
list_category_patterns
|
40
|
+
choosing_a_pattern
|
41
|
+
elsif input.to_i > 0 && input.to_i <= @categories.size
|
42
|
+
@input = @categories[input.to_i-1]
|
43
|
+
list_category_patterns
|
44
|
+
choosing_a_pattern
|
45
|
+
elsif input == "list"
|
46
|
+
puts "Interested in some more ideas, huh?"
|
47
|
+
list_categories
|
48
|
+
elsif input == "exit"
|
49
|
+
goodbye
|
50
|
+
else
|
51
|
+
print "Hmm, I'm not seeing that category. "
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def choosing_a_pattern
|
57
|
+
puts ""
|
58
|
+
puts "For more information on a specific pattern, please enter the corresponding number."
|
59
|
+
puts "Or if none of these patterns are jumping out at you, type 'list' to see the categories again."
|
60
|
+
puts "___________________________________________________________________________________________"
|
61
|
+
input = nil
|
62
|
+
while input != "exit"
|
63
|
+
input = gets.strip.downcase
|
64
|
+
|
65
|
+
if input.to_i > 0 && input.to_i <= KnittingPatterns::Pattern.all.size
|
66
|
+
pattern = KnittingPatterns::Pattern.all[input.to_i-1]
|
67
|
+
puts "___________________________________________________________________________________________"
|
68
|
+
puts "#{pattern.title}"
|
69
|
+
puts "___________________________________________________________________________________________"
|
70
|
+
KnittingPatterns::Scraper.new.scrape_selected_pattern("#{pattern.url}")
|
71
|
+
puts "___________________________________________________________________________________________"
|
72
|
+
puts "To visit the website directly click here ----> #{pattern.url}"
|
73
|
+
puts ""
|
74
|
+
puts "If you would like to see another pattern in this category, simply enter the corresponding number."
|
75
|
+
puts "If you would like to see the list of categories instead, type 'list'"
|
76
|
+
puts "___________________________________________________________________________________________"
|
77
|
+
elsif input == "list"
|
78
|
+
call
|
79
|
+
elsif input == "exit"
|
80
|
+
goodbye
|
81
|
+
else
|
82
|
+
puts "Hmm, I don't see that pattern. Let's try this again."
|
83
|
+
call
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def goodbye
|
89
|
+
puts "Thanks for stopping by! Come back anytime to review more knitting patterns!"
|
90
|
+
puts "___________________________________________________________________________________________"
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class KnittingPatterns::Scraper
|
2
|
+
|
3
|
+
def scrape_knit_categories
|
4
|
+
doc = Nokogiri::HTML(open("https://www.purlsoho.com/create/category/knit/knit-view-all/"))
|
5
|
+
category = doc.css("li.categories").css("ul").css("li").text.split("\n")
|
6
|
+
category
|
7
|
+
end
|
8
|
+
|
9
|
+
def scrape_category_patterns(user_input)
|
10
|
+
doc = Nokogiri::HTML(open("https://www.purlsoho.com/create/category/knit/knit-#{user_input}/"))
|
11
|
+
doc.css("li").css("h3").css("a").each do |pattern_info|
|
12
|
+
pattern = KnittingPatterns::Pattern.new
|
13
|
+
|
14
|
+
pattern.title = pattern_info.text
|
15
|
+
pattern.url = pattern_info.attribute("href").value
|
16
|
+
|
17
|
+
pattern.save
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def scrape_selected_pattern(pattern_url)
|
22
|
+
doc = Nokogiri::HTML(open("#{pattern_url}"))
|
23
|
+
doc.css("div.pf-content").css("p").each do |info|
|
24
|
+
puts "#{info.text.strip}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knitting_patterns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashley Bland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: :runtime
|
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: Provides information on the free knitting patterns from Purl Soho
|
84
|
+
email:
|
85
|
+
- ashleyjbland@gmail.com
|
86
|
+
executables:
|
87
|
+
- knitting_patterns
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- bin/knitting_patterns
|
92
|
+
- lib/knitting_patterns.rb
|
93
|
+
- lib/knitting_patterns/cli.rb
|
94
|
+
- lib/knitting_patterns/pattern.rb
|
95
|
+
- lib/knitting_patterns/scraper.rb
|
96
|
+
homepage: https://github.com/ashleyjbland/knitting_patterns
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.0.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Free Knitting Patterns from Purl Soho
|
119
|
+
test_files: []
|