Class: String

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

Instance Method Summary collapse

Instance Method Details

#cap_firstObject



57
58
59
60
61
# File 'lib/doing/helpers.rb', line 57

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

Parameters:

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

    Additional Options



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/doing/helpers.rb', line 92

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

#normalize_bool(default = :and) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/doing/helpers.rb', line 73

def normalize_bool(default = :and)
  case self
  when /(and|all)/i
    :and
  when /(any|or)/i
    :or
  when /(not|none)/i
    :not
  else
    default.is_a?(Symbol) ? default : default.normalize_bool
  end
end

#normalize_bool!Object

Returns Symbol :and, :or, or :not.

Returns:

  • Symbol :and, :or, or :not



69
70
71
# File 'lib/doing/helpers.rb', line 69

def normalize_bool!
  replace normalize_bool
end