module Card::Set::Helpers

These helper methods provide easy access to metadata, such as information about the set modified by a module. These methods are seldom used by Monkeys; they are primarily Platypus tools.

Constants

SET_PATTERN_TEST_REGEXP

Public Instance Methods

format_module(format_sym) click to toggle source
# File lib/card/set/helpers.rb, line 69
def format_module format_sym
  const_get Card::Format.format_class_name(format_sym)
end
format_modules(format_sym, test: true) click to toggle source
# File lib/card/set/helpers.rb, line 59
def format_modules format_sym, test: true
  if base_format_modules?
    [format_module(format_sym)]
  elsif abstract_set?
    abstract_format_modules format_sym, test
  else
    nonbase_format_modules format_sym
  end
end
method_missing(method_name, *args) click to toggle source

handles all_set?, abstract_set?, type_set?, etc.

Calls superclass method
# File lib/card/set/helpers.rb, line 35
def method_missing method_name, *args
  if (matches = method_name.match SET_PATTERN_TEST_REGEXP)
    pattern_code == matches[:pattern].to_sym
  else
    super
  end
end
modules() click to toggle source
# File lib/card/set/helpers.rb, line 49
def modules
  if all_set?
    [self]
  elsif abstract_set?
    [test_set]
  else
    Set.modules[:nonbase][shortname] || []
  end
end
pattern_code() click to toggle source

@return [Symbol] codename associated with set’s pattern. Eg :type, :right, etc

# File lib/card/set/helpers.rb, line 30
def pattern_code
  @pattern_code ||= set_name_parts[2].underscore.to_sym
end
respond_to_missing?(method_name, _include_private=false) click to toggle source

@return [true/false] handles all_set?, abstract_set?, type_set?, etc.

# File lib/card/set/helpers.rb, line 45
def respond_to_missing? method_name, _include_private=false
  method_name.match? SET_PATTERN_TEST_REGEXP
end
set_name_parts() click to toggle source

@return [Array] list of strings of parts of set module’s name Eg, returns [“Card”, “Set”, “Type”, “User”] for Card::Set::Type::User

# File lib/card/set/helpers.rb, line 25
def set_name_parts
  @set_name_parts ||= name.split "::"
end
shortname() click to toggle source

@return [String] short name of card module. For example, returns Type::User for Card::Set::Type::User

# File lib/card/set/helpers.rb, line 11
def shortname
  first = 2 # shortname eliminates Card::Set
  last = first + num_set_parts(pattern_code)
  set_name_parts[first..last].join "::"
end
underscored_name() click to toggle source

@return [String] name of card module with underscores. For example, returns Card__Set__Type__User for Card::Set::Type::User

# File lib/card/set/helpers.rb, line 19
def underscored_name
  shortname.tr(":", "_").underscore
end

Private Instance Methods

abstract_format_modules(format_sym, test) click to toggle source
# File lib/card/set/helpers.rb, line 109
def abstract_format_modules format_sym, test
  [(test ? test_set : self).format_module(format_sym)]
end
base_format_modules?() click to toggle source
# File lib/card/set/helpers.rb, line 105
def base_format_modules?
  !set_format_type_key || set_format_type_key == :base_format
end
nonbase_format_modules(format_sym) click to toggle source
# File lib/card/set/helpers.rb, line 113
def nonbase_format_modules format_sym
  format_class = Card::Format.format_class format: format_sym
  Card::Set.modules[set_format_type_key][format_class][shortname] || []
end
num_set_parts(pattern_code) click to toggle source
# File lib/card/set/helpers.rb, line 118
def num_set_parts pattern_code
  return 1 if pattern_code == :abstract

  Pattern.find(pattern_code).anchor_parts_count
end
set_format_type_key() click to toggle source

@return [Symbol] base_format,

# File lib/card/set/helpers.rb, line 76
def set_format_type_key
  @set_format_type_key ||= :"#{set_type_key}_format"
end
set_type_key() click to toggle source
# File lib/card/set/helpers.rb, line 80
def set_type_key
  if all_set?
    :base
  elsif abstract_set?
    :abstract
  else
    :nonbase
  end
end
test_set() click to toggle source
# File lib/card/set/helpers.rb, line 90
      def test_set
        # rubocop:disable Lint/Eval
        ::Card::Set::Self.const_remove_if_defined :TestSet
        eval <<-RUBY, binding, __FILE__, __LINE__ + 1
          class ::Card::Set::Self
            module TestSet
              extend Card::Set
              include_set #{name}
            end
          end
        RUBY
        ::Card::Set::Self::TestSet
        # rubocop:enable Lint/Eval
      end