Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/doing/wwid.rb

Instance Method Summary collapse

Instance Method Details

#cap_first ⇒ Object



48
49
50
51
52
# File 'lib/doing/wwid.rb', line 48

def cap_first
  sub(/^\w/) do |m|
    m.upcase
  end
end

Parameters:

  • opt (Hash) (defaults to: {}) —

    Additional Options



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/doing/wwid.rb', line 59

def link_urls(opt = {})
  opt[:format] ||= :html
  if opt[:format] == :html
    gsub(%r{(?mi)((http|https)://)?([\w\-_]+(\.[\w\-_]+)+)([\w\-.,@?^=%&:/~+#]*[\w\-@^=%&/~+#])?}) do |_match|
      m = Regexp.last_match
      proto = m[1].nil? ? 'http://' : ''
      %(<a href="#{proto}#{m[0]}" title="Link to #{m[0]}">[#{m[3]}]</a>)
    end.gsub(/<(\w+:.*?)>/) do |match|
      m = Regexp.last_match
      if m[1] =~ /<a href/
        match
      else
        %(<a href="#{m[1]}" title="Link to #{m[1]}">[link]</a>)
      end
    end
  else
    self
  end
end