Module: StringPresentBlank::String

Defined in:
lib/string_present_blank/string.rb

Instance Method Summary collapse

Instance Method Details

#blank(conditions = {}) ⇒ Object



17
18
19
# File 'lib/string_present_blank/string.rb', line 17

def blank(conditions={})
  present(conditions) == self ? '' : self
end

#present(conditions = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/string_present_blank/string.rb', line 3

def present(conditions={})
  if_condition = conditions.delete(:if)
  if_condition = true if if_condition.nil?

  unless_condition = conditions.delete(:unless)
  unless_condition = false if unless_condition.nil?

  if if_condition and not unless_condition
    self
  else
    ''
  end
end