module StringPresentBlank::String

Public Instance Methods

blank(conditions={}) click to toggle source
# File lib/string_present_blank/string.rb, line 23
def blank(conditions={})
  present(conditions) == self ? '' : self
end
present(conditions={}) click to toggle source
# File lib/string_present_blank/string.rb, line 3
def present(conditions={})
  if_condition = if conditions.has_key?(:if)
    conditions.delete(:if)
  else
    true
  end

  unless_condition = if conditions.has_key?(:unless)
    conditions.delete(:unless)
  else
    false
  end

  if if_condition and not unless_condition
    self
  else
    ''
  end
end