Class: Ubi::Memoria::Site

Inherits:
Base
  • Object
show all
Defined in:
lib/ubi/memorias/site.rb

Overview

A site, url and title?

Instance Attribute Summary collapse

Attributes inherited from Base

#hint, #opts, #text

Class Method Summary collapse

Instance Method Summary collapse

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

Returns the value of attribute link.



5
6
7
# File 'lib/ubi/memorias/site.rb', line 5

def link
  @link
end

#uriObject

Returns the value of attribute uri.



5
6
7
# File 'lib/ubi/memorias/site.rb', line 5

def uri
  @uri
end

Class Method Details

.keyObject



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

#formatObject

Prefix http:// if there isn’t one defined



24
25
26
# File 'lib/ubi/memorias/site.rb', line 24

def format
  text
end

#tld_parserObject



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