Class: Optic14n::CanonicalizedUrls
- Inherits:
-
Object
- Object
- Optic14n::CanonicalizedUrls
- Extended by:
- Forwardable
- Defined in:
- lib/optic14n/canonicalized_urls.rb
Overview
Canonicalizes a set of URLs
Instance Attribute Summary collapse
-
#each ⇒ Object
readonly
Returns the value of attribute each.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#output_set ⇒ Object
readonly
Returns the value of attribute output_set.
-
#seen ⇒ Object
readonly
Returns the value of attribute seen.
Class Method Summary collapse
-
.from_urls(urls, options = {}) ⇒ Object
Canonicalize given urls.
Instance Method Summary collapse
- #canonicalize! ⇒ Object
-
#initialize(urls, options) ⇒ CanonicalizedUrls
constructor
A new instance of CanonicalizedUrls.
- #write(filename) ⇒ Object
Constructor Details
#initialize(urls, options) ⇒ CanonicalizedUrls
Returns a new instance of CanonicalizedUrls.
13 14 15 16 |
# File 'lib/optic14n/canonicalized_urls.rb', line 13 def initialize(urls, ) @urls = urls @options = end |
Instance Attribute Details
#each ⇒ Object (readonly)
Returns the value of attribute each.
7 8 9 |
# File 'lib/optic14n/canonicalized_urls.rb', line 7 def each @each end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
7 8 9 |
# File 'lib/optic14n/canonicalized_urls.rb', line 7 def failures @failures end |
#output_set ⇒ Object (readonly)
Returns the value of attribute output_set.
7 8 9 |
# File 'lib/optic14n/canonicalized_urls.rb', line 7 def output_set @output_set end |
#seen ⇒ Object (readonly)
Returns the value of attribute seen.
7 8 9 |
# File 'lib/optic14n/canonicalized_urls.rb', line 7 def seen @seen end |
Class Method Details
.from_urls(urls, options = {}) ⇒ Object
Canonicalize given urls. options
will be passed to BLURI.parse
43 44 45 |
# File 'lib/optic14n/canonicalized_urls.rb', line 43 def self.from_urls(urls, = {}) CanonicalizedUrls.new(urls, ).tap(&:canonicalize!) end |
Instance Method Details
#canonicalize! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/optic14n/canonicalized_urls.rb', line 18 def canonicalize! @seen = 0 @failures = {} @output_set = Set.new @urls.each do |url| begin @output_set.add(BLURI(url).canonicalize!(@options)) rescue StandardError => e failures[url] = e end @seen += 1 end end |
#write(filename) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/optic14n/canonicalized_urls.rb', line 33 def write(filename) File.open(filename, "w") do |file| @output_set.each do |url| file.puts url end end end |