verify_urls 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: 762598ccd9cd247e8829262437a63aeac8f1f521bde3780d79ea64dfde507ba3
4
+ data.tar.gz: 8730ba76a753622d333a5a44c5df099e0d1e666bd64aa99050ec1480154f46e2
5
+ SHA512:
6
+ metadata.gz: 68d964a2f4ee4a0a22c6632b9f1c2e0505022bea1a358cdaeee973d597dbdf713879314588b4f55cf4cc3458bb886afac15e3f2974a28cd7d0517f27c0b072a8
7
+ data.tar.gz: 5586d03a3974974476f18c8469fd67e808d14246350102202e24530da85e885c87c239b2a682c0b35b7972fc110bf6e187115aa9e5226da858b1872016531bd3
data/.gitignore ADDED
@@ -0,0 +1,14 @@
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
12
+
13
+ .byebug_history
14
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_from: .ruby-style-guide.yml
2
+ AllCops:
3
+ UseCache: true
4
+ CacheRootDirectory: tmp
5
+ Exclude:
6
+ - 'tmp/*.rb'
@@ -0,0 +1,265 @@
1
+ Rails:
2
+ Enabled: false
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+ Exclude:
6
+ - "vendor/**/*"
7
+ UseCache: true
8
+ Style/CollectionMethods:
9
+ Description: Preferred collection methods.
10
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
11
+ Enabled: true
12
+ PreferredMethods:
13
+ collect: map
14
+ collect!: map!
15
+ find: detect
16
+ find_all: select
17
+ reduce: inject
18
+ Style/RedundantFreeze:
19
+ Description: "Checks usages of Object#freeze on immutable objects."
20
+ Enabled: false
21
+ Layout/DotPosition:
22
+ Description: Checks the position of the dot in multi-line method calls.
23
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
24
+ Enabled: true
25
+ EnforcedStyle: trailing
26
+ SupportedStyles:
27
+ - leading
28
+ - trailing
29
+ Naming/FileName:
30
+ Description: Use snake_case for source file names.
31
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
32
+ Enabled: false
33
+ Exclude: []
34
+ Naming/MemoizedInstanceVariableName:
35
+ Description: Memoized method name should match memo instance variable name.
36
+ Enabled: false
37
+ Naming/UncommunicativeMethodParamName:
38
+ Description: >-
39
+ Checks for method parameter names that contain capital letters,
40
+ end in numbers, or do not meet a minimal length.
41
+ Enabled: false
42
+ Style/GuardClause:
43
+ Description: Check for conditionals that can be replaced with guard clauses
44
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
45
+ Enabled: true
46
+ MinBodyLength: 3
47
+ Style/IfUnlessModifier:
48
+ Description: Favor modifier if/unless usage when you have a single-line body.
49
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
50
+ Enabled: false
51
+ Style/OptionHash:
52
+ Description: Don't use option hashes when you can use keyword arguments.
53
+ Enabled: false
54
+ Style/PercentLiteralDelimiters:
55
+ Description: Use `%`-literal delimiters consistently
56
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
57
+ Enabled: false
58
+ PreferredDelimiters:
59
+ "%": "()"
60
+ "%i": "()"
61
+ "%q": "()"
62
+ "%Q": "()"
63
+ "%r": "{}"
64
+ "%s": "()"
65
+ "%w": "()"
66
+ "%W": "()"
67
+ "%x": "()"
68
+ Naming/PredicateName:
69
+ Description: Check the names of predicate methods.
70
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
71
+ Enabled: true
72
+ NamePrefix:
73
+ - is_
74
+ - has_
75
+ - have_
76
+ NamePrefixBlacklist:
77
+ - is_
78
+ Exclude:
79
+ - spec/**/*
80
+ Style/RaiseArgs:
81
+ Description: Checks the arguments passed to raise/fail.
82
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
83
+ Enabled: false
84
+ EnforcedStyle: exploded
85
+ SupportedStyles:
86
+ - compact
87
+ - exploded
88
+ Style/SignalException:
89
+ Description: Checks for proper usage of fail and raise.
90
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
91
+ Enabled: false
92
+ EnforcedStyle: semantic
93
+ SupportedStyles:
94
+ - only_raise
95
+ - only_fail
96
+ - semantic
97
+ Style/SingleLineBlockParams:
98
+ Description: Enforces the names of some block params.
99
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
100
+ Enabled: false
101
+ Methods:
102
+ - reduce:
103
+ - a
104
+ - e
105
+ - inject:
106
+ - a
107
+ - e
108
+ Style/TrivialAccessors:
109
+ Enabled: false
110
+ Style/SingleLineMethods:
111
+ Description: Avoid single-line methods.
112
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
113
+ Enabled: false
114
+ AllowIfMethodIsEmpty: true
115
+ Style/StringLiterals:
116
+ Description: Checks if uses of quotes match the configured preference.
117
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
118
+ Enabled: true
119
+ EnforcedStyle: single_quotes
120
+ SupportedStyles:
121
+ - single_quotes
122
+ - double_quotes
123
+ Style/MixinUsage:
124
+ Enabled: true
125
+ Exclude:
126
+ - exe/*
127
+ Style/StringLiteralsInInterpolation:
128
+ Description: Checks if uses of quotes inside expressions in interpolated strings
129
+ match the configured preference.
130
+ Enabled: true
131
+ EnforcedStyle: single_quotes
132
+ SupportedStyles:
133
+ - single_quotes
134
+ - double_quotes
135
+ Style/TrailingCommaInArrayLiteral:
136
+ Description: Checks for trailing comma in parameter lists and literals.
137
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
138
+ Enabled: true
139
+ EnforcedStyleForMultiline: comma
140
+ Style/TrailingCommaInHashLiteral:
141
+ Description: Checks for trailing comma in parameter lists and literals.
142
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
143
+ Enabled: true
144
+ EnforcedStyleForMultiline: comma
145
+ Metrics/AbcSize:
146
+ Description: A calculated magnitude based on number of assignments, branches, and
147
+ conditions.
148
+ Enabled: false
149
+ Max: 15
150
+ Metrics/ClassLength:
151
+ Description: Avoid classes longer than 100 lines of code.
152
+ Enabled: false
153
+ CountComments: false
154
+ Max: 100
155
+ Metrics/ModuleLength:
156
+ CountComments: false
157
+ Max: 100
158
+ Description: Avoid modules longer than 100 lines of code.
159
+ Enabled: false
160
+ Metrics/CyclomaticComplexity:
161
+ Description: A complexity metric that is strongly correlated to the number of test
162
+ cases needed to validate a method.
163
+ Enabled: false
164
+ Max: 6
165
+ Metrics/MethodLength:
166
+ Description: Avoid methods longer than 10 lines of code.
167
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
168
+ Enabled: false
169
+ CountComments: false
170
+ Max: 10
171
+ Metrics/ParameterLists:
172
+ Description: Avoid parameter lists longer than three or four parameters.
173
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
174
+ Enabled: false
175
+ Max: 5
176
+ CountKeywordArgs: true
177
+ Metrics/PerceivedComplexity:
178
+ Description: A complexity metric geared towards measuring complexity for a human
179
+ reader.
180
+ Enabled: false
181
+ Max: 7
182
+ Metrics/LineLength:
183
+ Description: Maximum line length
184
+ Enabled: true
185
+ Max: 95
186
+ Exclude:
187
+ - exe/verify_urls
188
+ - lib/verify_urls/cli.rb
189
+ - Gemfile
190
+ - verify_urls.gemspec
191
+ - spec/**/*
192
+ Metrics/BlockLength:
193
+ Enabled: true
194
+ Exclude:
195
+ - lib/verify_urls/cli/*
196
+ - spec/**/*
197
+ Lint/AssignmentInCondition:
198
+ Description: Don't use assignment in conditions.
199
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
200
+ Enabled: false
201
+ AllowSafeAssignment: true
202
+ Style/InlineComment:
203
+ Description: Avoid inline comments.
204
+ Enabled: false
205
+ Naming/AccessorMethodName:
206
+ Description: Check the naming of accessor methods for get_/set_.
207
+ Enabled: false
208
+ Style/Alias:
209
+ Description: Use alias_method instead of alias.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
211
+ Enabled: false
212
+ Style/Documentation:
213
+ Description: Document classes and non-namespace modules.
214
+ Enabled: false
215
+ Style/DoubleNegation:
216
+ Description: Checks for uses of double negation (!!).
217
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
218
+ Enabled: false
219
+ Style/EachWithObject:
220
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
221
+ Enabled: false
222
+ Style/EmptyLiteral:
223
+ Description: Prefer literals to Array.new/Hash.new/String.new.
224
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
225
+ Enabled: false
226
+ Style/ModuleFunction:
227
+ Description: Checks for usage of `extend self` in modules.
228
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
229
+ Enabled: false
230
+ Style/OneLineConditional:
231
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
232
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
233
+ Enabled: false
234
+ Style/PerlBackrefs:
235
+ Description: Avoid Perl-style regex back references.
236
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
237
+ Enabled: false
238
+ Style/Send:
239
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
240
+ may overlap with existing methods.
241
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
242
+ Enabled: false
243
+ Style/SpecialGlobalVars:
244
+ Description: Avoid Perl-style global variables.
245
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
246
+ Enabled: false
247
+ Style/VariableInterpolation:
248
+ Description: Don't interpolate global, instance and class variables directly in
249
+ strings.
250
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
251
+ Enabled: false
252
+ Style/WhenThen:
253
+ Description: Use when x then ... for one-line cases.
254
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
255
+ Enabled: false
256
+ Lint/EachWithObjectArgument:
257
+ Description: Check for immutable argument given to each_with_object.
258
+ Enabled: true
259
+ Lint/HandleExceptions:
260
+ Description: Don't suppress exception.
261
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
262
+ Enabled: false
263
+ Lint/LiteralInInterpolation:
264
+ Description: Checks for literals used in interpolation.
265
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in verify_urls.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jacob Burenstam Linder
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,82 @@
1
+ # VerifyUrls
2
+
3
+ Verify URL(s) with ease - CLI and Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'verify_urls'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install verify_urls
20
+
21
+ ## Usage
22
+
23
+ __Command Line Interface (CLI)__
24
+
25
+ ```
26
+ Usage: verify_urls --help
27
+ --file=README.md The file that contains the URLs to verify.
28
+ --format=markdown The file format (optional) - one of markdown, html, csv (if none given we'll try to infer it from the file path).
29
+ --output=output.csv CSV Output path
30
+ --[no-]error-failed Exit with non-zero status if any URL(s) failed.
31
+ -h, --help How to use
32
+ ```
33
+
34
+ __Ruby__
35
+
36
+ Verify all URLs in `README.md`
37
+
38
+ ```ruby
39
+ reader = VerifyUrls::Reader.new('README.md')
40
+ reader.urls.each do |url|
41
+ response = VerifyUrls::Helper.GET(url)
42
+ puts "Failed: #{url}" if response&.code != 200
43
+ end
44
+ ```
45
+
46
+ Get all URLs in `README.md`:
47
+
48
+ ```ruby
49
+ require 'verify_urls'
50
+
51
+ reader = VerifyUrls::Reader.new('README.md')
52
+ reader.urls # => ["https://rubygems.org", "https://opensource.org/licenses/MIT"]
53
+
54
+ # we will try to infer the file format from the file extension
55
+ # you can explicitly provide it
56
+ reader = VerifyUrls::Reader.new('README', 'markdown')
57
+ reader.urls # => ["https://rubygems.org", "https://opensource.org/licenses/MIT"]
58
+ ```
59
+
60
+ HTML and CSV is also supported
61
+
62
+ ```ruby
63
+ reader = VerifyUrls::Reader.new('index.html') # get all anchor hrefs
64
+ reader.urls # => ["https://example.com"]
65
+
66
+ reader = VerifyUrls::Reader.new('output.csv') # assumes no header and URL to be in the first column
67
+ reader.urls # => ["https://example.com"]
68
+ ```
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+
74
+ 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).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/buren/verify_urls.
79
+
80
+ ## License
81
+
82
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'verify_urls'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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
data/exe/verify_urls ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # for dev purposes
5
+ require 'bundler/setup' if ENV['VERIFY_URLS_GEM_DEV']
6
+ require 'verify_urls'
7
+ require 'verify_urls/cli'
8
+
9
+ options = VerifyUrls::CLI.parse(argv: ARGV)
10
+
11
+ file_path = options.fetch(:file) { raise(ArgumentError, '--file is required') }
12
+ file_format = options[:format]
13
+
14
+ helper = VerifyUrls::Helper
15
+ reader = VerifyUrls::Reader.new(file_path, file_format)
16
+ urls = reader.urls
17
+
18
+ failed_urls = []
19
+ success_urls = []
20
+ skipped_urls = []
21
+ puts "Found #{urls.length} URLs in README.md"
22
+ urls.each do |url|
23
+ unless helper.absolute_url?(url)
24
+ # Consider validating internal links such as: "#license" and "LICENSE"
25
+ puts "[Skipped] #{url}.. not an absolute URL!"
26
+ skipped_urls << url
27
+ next
28
+ end
29
+
30
+ print "[Fetching] #{url}.."
31
+ response = helper.GET(url)
32
+ if helper.response_success?(response)
33
+ puts "#{response.code} #{response.reason}!"
34
+ success_urls << url
35
+ else
36
+ puts "#{response&.code} #{response&.reason || 'error'}!"
37
+ failed_urls << url
38
+ end
39
+ end
40
+
41
+ if file_path = options[:output]
42
+ csv_string = CSV.generate do |csv|
43
+ csv << %w[success failed checked skipped url]
44
+ failed_urls.each { |url| csv << [false, true, true, false, url] }
45
+ success_urls.each { |url| csv << [true, false, true, false, url] }
46
+ skipped_urls.each { |url| csv << [false, false, false, true, url] }
47
+ end
48
+ File.write(file_path, csv_string)
49
+ end
50
+
51
+ puts
52
+ puts '[Finished]'
53
+ puts "Found #{urls.length}"
54
+ puts "Checked #{failed_urls.length + success_urls.length}"
55
+ puts "Skipped #{skipped_urls.length}"
56
+ puts "Failed #{failed_urls.length}"
57
+
58
+ if options.fetch(:error_failed, false) && failed_urls.length > 0
59
+ puts
60
+ puts "[ERROR] #{failed_urls} URL(s) failed!"
61
+ exit 1
62
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module VerifyUrls
6
+ class CLI
7
+ def self.parse(argv:)
8
+ options = {}
9
+ OptionParser.new do |parser|
10
+ parser.banner = 'Usage: verify_urls --help'
11
+ parser.default_argv = argv
12
+
13
+ parser.on('--file=README.md', String, 'The file that contains the URLs to verify.') do |string|
14
+ options[:file] = string
15
+ end
16
+
17
+ parser.on('--format=markdown', String, "The file format (optional) - one of markdown, html, csv (if none given we'll try to infer it from the file path).") do |string|
18
+ options[:format] = string
19
+ end
20
+
21
+ parser.on('--output=output.csv', String, 'CSV Output path') do |string|
22
+ options[:output] = string
23
+ end
24
+
25
+ parser.on('--[no-]error-failed', 'Exit with non-zero status if any URL(s) failed.') do |boolean|
26
+ options[:error_failed] = boolean
27
+ end
28
+
29
+ parser.on('-h', '--help', 'How to use') do
30
+ puts parser
31
+ exit
32
+ end
33
+ end.parse!
34
+ options
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'uri'
5
+
6
+ module VerifyUrls
7
+ module Helper
8
+ def self.response_success?(response)
9
+ code = response&.code
10
+ code && code >= 200 && code < 300
11
+ end
12
+
13
+ def self.GET(url)
14
+ HTTP.follow.get(url)
15
+ rescue HTTP::Error => _e
16
+ end
17
+
18
+ def self.absolute_url?(url)
19
+ uri = URI.parse(url)
20
+ return false unless uri.hostname
21
+ return false unless uri.scheme
22
+ return false unless uri.absolute?
23
+ true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'http'
5
+ require 'nokogiri'
6
+ require 'kramdown'
7
+
8
+ module VerifyUrls
9
+ class Reader
10
+ attr_reader :file, :file_path
11
+
12
+ def initialize(file_path, file_format = nil)
13
+ @file = File.read(file_path)
14
+ @file_path = file_path
15
+ @file_format = file_format
16
+ end
17
+
18
+ def urls
19
+ case file_format.to_s.downcase
20
+ when 'markdown', 'md' then markdown_urls(file)
21
+ when 'html' then html_urls(file)
22
+ when 'csv' then csv_urls(file)
23
+ else
24
+ raise(ArgumentError, "unknown format #{file_format}")
25
+ end
26
+ end
27
+
28
+ def file_format
29
+ @file_format || @file_path.split('.').last
30
+ end
31
+
32
+ private
33
+
34
+ def csv_urls(file)
35
+ CSV.parse(file).map(&:first).compact
36
+ end
37
+
38
+ def html_urls(file)
39
+ document = Nokogiri::HTML(file)
40
+ document.css('a').map { |e| e['href'] }.compact
41
+ end
42
+
43
+ def markdown_urls(file)
44
+ html = Kramdown::Document.new(file).to_html
45
+ html_urls(html)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VerifyUrls
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'verify_urls/version'
4
+ require 'verify_urls/reader'
5
+ require 'verify_urls/helper'
6
+
7
+ module VerifyUrls
8
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'verify_urls/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'verify_urls'
9
+ spec.version = VerifyUrls::VERSION
10
+ spec.authors = ['Jacob Burenstam']
11
+ spec.email = ['burenstam@gmail.com']
12
+
13
+ spec.summary = 'Verify URL(s)'
14
+ spec.description = 'Verify URL(s) with ease - CLI and Ruby.'
15
+ spec.homepage = 'https://github.com/buren/verify_urls'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'http', '~> 3.3'
28
+ # TODO: Consider making kramdown & nokogiri optional
29
+ spec.add_dependency 'kramdown', '~> 1.17'
30
+ spec.add_dependency 'nokogiri', '~> 1.8'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
33
+ spec.add_development_dependency 'byebug'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: verify_urls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Burenstam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kramdown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Verify URL(s) with ease - CLI and Ruby.
112
+ email:
113
+ - burenstam@gmail.com
114
+ executables:
115
+ - verify_urls
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".ruby-style-guide.yml"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - exe/verify_urls
131
+ - lib/verify_urls.rb
132
+ - lib/verify_urls/cli.rb
133
+ - lib/verify_urls/helper.rb
134
+ - lib/verify_urls/reader.rb
135
+ - lib/verify_urls/version.rb
136
+ - verify_urls.gemspec
137
+ homepage: https://github.com/buren/verify_urls
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.7.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Verify URL(s)
161
+ test_files: []