Class: String

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

Instance Method Summary collapse

Instance Method Details

#cap_firstObject



9
10
11
12
13
# File 'lib/doing/wwid.rb', line 9

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

Parameters:

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

    Additional Options



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/doing/wwid.rb', line 20

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