fontpair 0.1.0.1 → 0.2.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 +5 -5
- data/bin/fontpair +9 -2
- data/lib/fontpair.rb +1 -0
- data/lib/fontpair/fetcher.rb +40 -0
- data/lib/fontpair/search.rb +4 -9
- data/lib/fontpair/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc9d4e5aaabd9df47982850b111954f43615c3529a8b1aeb52d38728da984c22
|
4
|
+
data.tar.gz: 73f757c0e3498dd31082acc3a29789a5b024017a502a1ce43846e0beb5de200b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1664163c6157efd81dedb5fc813078f1a98755dffee03456311c0e38f1225c933ad6c3f922a301e1120b89d5df040df8e5ffa1a3c2b2ef842c89af4226cf21
|
7
|
+
data.tar.gz: e35a07e6e9bf3139d54f865ce43eb58150de10e20cbc37ef4680f9cbd83e73543d9378e215efed5194e8f2e1267505e820b334fde6b1aada33d1e20b74c32e37
|
data/bin/fontpair
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
require_relative '../lib/fontpair'
|
5
5
|
require 'optparse'
|
6
6
|
|
7
|
+
filename = File::expand_path('~/.fontpairs')
|
8
|
+
|
7
9
|
OptionParser.new do |opts|
|
8
10
|
opts.banner = 'Usage: fontpair <fontname>'
|
9
11
|
|
@@ -16,8 +18,13 @@ OptionParser.new do |opts|
|
|
16
18
|
$stderr.puts 'You must specify a font to pair.'
|
17
19
|
exit 1
|
18
20
|
end
|
19
|
-
|
20
|
-
|
21
|
+
|
22
|
+
fetcher = FontPair::Fetcher.new(filename)
|
23
|
+
fetcher.fetch unless File::exists?(filename)
|
24
|
+
|
25
|
+
results = FontPair::Search.new(font, filename)
|
21
26
|
results.pretty_print
|
27
|
+
|
28
|
+
fetcher.fetch if File::exists?(filename)
|
22
29
|
end
|
23
30
|
end.parse!
|
data/lib/fontpair.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module FontPair
|
2
|
+
##
|
3
|
+
# Fetches a copy of the pairs available on FontPair.co locally.
|
4
|
+
class Fetcher
|
5
|
+
SOURCE_URL = 'http://fontpair.co'.freeze
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
@filename = filename.freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch
|
12
|
+
return initialize_pairs unless File::exists?(@filename)
|
13
|
+
update_pairs
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize_pairs
|
19
|
+
pairs = fetch_pairs
|
20
|
+
File::open(@filename, 'w') { |file| file.puts pairs.join("\n") }
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_pairs
|
24
|
+
pairs = fetch_pairs
|
25
|
+
|
26
|
+
File::open(@filename, 'w+') do |file|
|
27
|
+
puts file.readlines
|
28
|
+
file.puts pairs.join("\n") unless file.read == pairs
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch_pairs
|
33
|
+
request = Net::HTTP.get(URI(SOURCE_URL))
|
34
|
+
page = Nokogiri::HTML(request)
|
35
|
+
|
36
|
+
page.css('.fontName').map { |pair| pair.content }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/lib/fontpair/search.rb
CHANGED
@@ -4,9 +4,8 @@ module FontPair
|
|
4
4
|
class Search
|
5
5
|
attr_reader :pairs
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(typeface)
|
7
|
+
def initialize(typeface, path)
|
8
|
+
@path = path
|
10
9
|
@typeface = typeface.downcase
|
11
10
|
@pairs = find_pairs
|
12
11
|
end
|
@@ -24,12 +23,8 @@ module FontPair
|
|
24
23
|
private
|
25
24
|
|
26
25
|
def find_pairs
|
27
|
-
|
28
|
-
font_pairs
|
29
|
-
|
30
|
-
# Delete the sections' headings and filter the pairs.
|
31
|
-
font_pairs.select { |pair| pair.downcase.match(%r{\band\b}) }
|
32
|
-
.select { |pair| pair.downcase.match(%r{\b#{@typeface}\b}) }
|
26
|
+
font_pairs = File::readlines(@path)
|
27
|
+
font_pairs.select { |pair| pair.downcase.match(@typeface) }
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
data/lib/fontpair/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontpair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dom Corvasce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- bin/fontpair
|
35
35
|
- lib/fontpair.rb
|
36
|
+
- lib/fontpair/fetcher.rb
|
36
37
|
- lib/fontpair/search.rb
|
37
38
|
- lib/fontpair/version.rb
|
38
39
|
homepage: https://github.com/domcorvasce/fontpair
|
@@ -55,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
56
|
version: '0'
|
56
57
|
requirements: []
|
57
58
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.7.3
|
59
60
|
signing_key:
|
60
61
|
specification_version: 4
|
61
62
|
summary: Pair fonts directly from command-line
|