Class: Card::Content::Chunk::URI
- Defined in:
- mod/core/chunk/uri.rb
Constant Summary collapse
- SCHEMES =
%w(irc http https ftp ssh git sftp file ldap ldaps mailto).freeze
- REJECTED_PREFIX_RE =
%w{! ": " ' ](}.map { |s| Regexp.escape s } * "|"
Instance Attribute Summary collapse
-
#link_text ⇒ Object
readonly
Returns the value of attribute link_text.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from Abstract
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Abstract
#as_json, #card, #format, full_re, #initialize, #inspect, #reference_code, #to_s
Constructor Details
This class inherits a constructor from Card::Content::Chunk::Abstract
Instance Attribute Details
#link_text ⇒ Object (readonly)
Returns the value of attribute link_text.
27 28 29 |
# File 'mod/core/chunk/uri.rb', line 27 def link_text @link_text end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
27 28 29 |
# File 'mod/core/chunk/uri.rb', line 27 def uri @uri end |
Class Method Details
.context_ok?(content, chunk_start) ⇒ Boolean
48 49 50 51 |
# File 'mod/core/chunk/uri.rb', line 48 def context_ok? content, chunk_start preceding_string = content[chunk_start - 2..chunk_start - 1] !(preceding_string =~ /(?:#{REJECTED_PREFIX_RE})$/) end |
.full_match(content, prefix) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'mod/core/chunk/uri.rb', line 37 def full_match content, prefix prepend_str = if prefix[-1, 1] != ":" && config[:prepend_str] config[:prepend_str] else "" end content = prepend_str + content match = super content, prefix [match, prepend_str.length] end |
Instance Method Details
#interpret(match, _content) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'mod/core/chunk/uri.rb', line 54 def interpret match, _content chunk = match[0] last_char = chunk[-1, 1] chunk.gsub!(/(?: )+/, "") @trailing_punctuation = if %w{, . ) ! ? :}.member?(last_char) @text.chop! chunk.chop! last_char end chunk.sub!(/\.$/, "") @link_text = chunk @uri = ::URI.parse(chunk) @process_chunk = process_uri_chunk rescue ::URI::Error => e # warn "rescue parse #{chunk_class}: # '#{m}' #{e.inspect} #{e.backtrace*"\n"}" Rails.logger.warn "rescue parse #{self.class}: #{e.inspect}" end |