Class: AdvancedBilling::IncludeNullOrNotNull

Inherits:
Object
  • Object
show all
Defined in:
lib/advanced_billing/models/include_null_or_not_null.rb

Overview

Allows to filter by ‘not_null` or `null`.

Constant Summary collapse

INCLUDE_NULL_OR_NOT_NULL =
[
  # TODO: Write general description for NOT_NULL
  NOT_NULL = 'not_null'.freeze,

  # TODO: Write general description for NULL
  NULL = 'null'.freeze
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = NOT_NULL) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/advanced_billing/models/include_null_or_not_null.rb', line 23

def self.from_value(value, default_value = NOT_NULL)
  return default_value if value.nil?

  str = value.to_s.strip

  case str.downcase
  when 'not_null' then NOT_NULL
  when 'null' then NULL
  else
    default_value
  end
end

.validate(value) ⇒ Object



17
18
19
20
21
# File 'lib/advanced_billing/models/include_null_or_not_null.rb', line 17

def self.validate(value)
  return false if value.nil?

  INCLUDE_NULL_OR_NOT_NULL.include?(value)
end