Class: Ubi::Memoria::Site
Overview
A site, url and title?
Instance Attribute Summary collapse
-
#link ⇒ Object
Returns the value of attribute link.
-
#uri ⇒ Object
Returns the value of attribute uri.
Attributes inherited from Base
Class Method Summary collapse
- .key ⇒ Object
-
.regex(_hint) ⇒ Object
Regex only for *.tld %r?)+)(?:/|.) (?:??)[a-zA-Z0-9-._?,'/\+&%$#=~]+.
Instance Method Summary collapse
-
#format ⇒ Object
Prefix http:// if there isn’t one defined.
-
#initialize(text, _hint = nil, opts = {}) ⇒ Site
constructor
A new instance of Site.
- #tld_parser ⇒ Object
Methods inherited from Base
#==, extract_text, inherited, name, parse, parse!, #parser, plural, #to_s
Constructor Details
#initialize(text, _hint = nil, opts = {}) ⇒ Site
Returns a new instance of Site.
7 8 9 10 11 12 13 |
# File 'lib/ubi/memorias/site.rb', line 7 def initialize(text, _hint = nil, opts = {}) text = text.downcase.gsub(/^\(|\.$/, '') text = "http://#{text}" unless text =~ %r{^\w{3,5}://} @text = text @link = tld_parser @opts = opts end |
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
5 6 7 |
# File 'lib/ubi/memorias/site.rb', line 5 def link @link end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/ubi/memorias/site.rb', line 5 def uri @uri end |
Class Method Details
.key ⇒ Object
52 53 54 |
# File 'lib/ubi/memorias/site.rb', line 52 def key :site end |
.regex(_hint) ⇒ Object
Regex only for *.tld %r?)+)(?:/|.) (?:??)[a-zA-Z0-9-._?,'/\+&%$#=~]+
%rhref="a-zA-Z0-9\-\.">https?://)?(?:www.)?+.[a-zA-Z]{2,3}
((?:https://)|(?:http://)|(?:www.))?(. [a-zA-Z]{2,3}(?:??)[a-zA-Z0-9-._?,'/\&%$#=~]+)
www.regexr.com/3bkne /([(https?)://(www.)?a-zA-Z0-9:@%._+~#=]2,256.[a-z]2,6b (?:[-a-zA-Z0-9@:%_+.~#?&//?=]*))/
without @
44 45 46 47 48 49 50 |
# File 'lib/ubi/memorias/site.rb', line 44 def regex(_hint) %r{ ([(https?)://(www\.)?a-zA-Z0-9:%\._\+~#=]{2,256} \.[a-z]{2,6}\b (?:[-a-zA-Z0-9@:%_\+.~#?&//?=]*)) }x end |
Instance Method Details
#format ⇒ Object
Prefix http:// if there isn’t one defined
24 25 26 |
# File 'lib/ubi/memorias/site.rb', line 24 def format text end |
#tld_parser ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ubi/memorias/site.rb', line 15 def tld_parser @uri = URI.parse(text) @link = PublicSuffix.parse(uri.host) rescue PublicSuffix::DomainInvalid nil end |