Sha256: dbd78b537302ac2130ed2b37b51b13a16b3a8f8d53396bddcbd77d438b54bd8b

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "code_ape/version"

require "code_ape/constants"

require "code_ape/section"
require "code_ape/subsection"
require "code_ape/division"
require "code_ape/group"
require "code_ape/class"

# All CodeApe functionality
module CodeApe
  # Takes a ape code and returns data if possible
  # @param code [String] The ape code to search
  # @return [CodeApe::Subsection, CodeApe::Division, CodeApe::Group, CodeApe::Class, nil] the ape code data
  def self.ape(code)
    upcased_code = code&.upcase

    case upcased_code
    when REGEX_SUBSECTION
      SUBSECTIONS.find { |e| e.key == upcased_code }
    when REGEX_DIVISION
      DIVISIONS.find { |e| e.key == upcased_code || e.key.delete(".") == upcased_code }
    when REGEX_GROUP
      GROUPS.find { |e| e.key == upcased_code || e.key.delete(".") == upcased_code }
    when REGEX_CLASS
      CLASSES.find { |e| e.key == upcased_code || e.key.delete(".") == upcased_code }
    end
  end

  # Takes a section code and returns data if possible
  # @param code [String] The section code to search
  # @return [CodeApe::Section, nil] the section code data
  def self.section(code)
    SECTIONS.find { |e| e.key == code&.upcase }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
code_ape-3.0.0 lib/code_ape.rb