class MtgApi::Utilities::WhiteList

a class that validates that the initialization value is contained in the list stored on the class

Attributes

list[RW]

the list of available values

value[RW]

the value of this instance of a whitelist

Public Class Methods

new(value) click to toggle source

store and validate the given value

# File lib/mtg_api/utilities/white_list.rb, line 12
def initialize(value)
  self.value = value
  fail ArgumentError, "Invalid value given: #{value.inspect}" unless valid?
end

Private Instance Methods

valid?() click to toggle source

whether or not the given value is valid

# File lib/mtg_api/utilities/white_list.rb, line 25
def valid?
  if value.is_a?(Array)
    (value - self.class.list).none?
  else
    self.class.list.include?(value)
  end
end