class OUT

Main Struct subclass for in-memory type representation. Instances of the base `CHECKING::YOU::IN` Struct will refer to only one of these, and this matching object will contain all relevant data about the type, such as file extension(s), `magic` bytes, and variations of a base type like all of:

…will be represented in a single `CHECKING::YOU::OUT` object.

Constants

GEM_PACKAGE_TIME

Time object representing the day this running CYO Gem was packaged.

`Gem::Specification#date` can be slightly misleading when developing locally with Bundler using `bundle exec`. One might expect the result of `#date` to be “now” (including hours/minutes/seconds) in UTC for such a runtime-packaged Gem, but it will always be midnight UTC of the current day (also in UTC), i.e. a date that is always in the past.

After ${your-UTC-offset} hours before midnight localtime, this will give you a day that seems to be in the future compared to a system clock displaying localtime despite that date UTC still being in the past, e.g. as I write this comment at 2021-05-25 22:22 PST, `GEM_PACKAGE_TIME.call` returns `2021-05-26 00:00:00 UTC`.

Rescue from `Gem::MissingSpecError`'s parent to support developing locally with just `require_relative` and no Bundler.

[0]: unless you manage to `bundle exec` at exactly 00:00:00 UTC :)

GEM_ROOT

Absolute path to the root of the Gem — the directory containing `bin`,`docs`,`lib`, etc.

POSTFIX_KEY

Get a CYO, Set, or nil by file-extension, e.g. `doc` => { CYO msword, CYO rtf }.

Species

Attributes

children[R]
description[RW]

Storage for descriptions (`<comment>`), acrnyms, suitable iconography, and other boring metadata, e.g.:

<mime-type type="application/vnd.oasis.opendocument.text">
  <comment>ODT document</comment>
  <acronym>ODT</acronym>
  <expanded-acronym>OpenDocument Text</expanded-acronym>
  <generic-icon name="x-office-document"/>
  […]
</mini-type>
parents[R]

Public Class Methods

all_night() click to toggle source

Main memoization Hash for our loaded Type data. { CHECKING::YOU::IN => CHECKING::YOU::OUT }

# File lib/checking-you-out/inner_spirit.rb, line 76
def self.all_night; @all_night ||= Hash.new(nil); end
from_glob(stick_around) click to toggle source

Get a Hash or nil for arbitrary non-file-extension glob match of a File basename.

# File lib/checking-you-out/inner_spirit.rb, line 108
def self.from_glob(stick_around)
  self.instance_variable_get(:@stick_around).select { |k,v|
    k.eql?(stick_around)
  }.yield_self { |matched|
    matched.empty? ? nil : matched
  }
end
from_pathname(pathname) click to toggle source
# File lib/checking-you-out/inner_spirit.rb, line 116
def self.from_pathname(pathname)
  return self.from_glob(pathname) || self.from_postfix(pathname)
end
from_postfix(stick_around) click to toggle source
# File lib/checking-you-out/inner_spirit.rb, line 103
def self.from_postfix(stick_around)
  self.instance_variable_get(:@after_forever)[POSTFIX_KEY.call(stick_around)]
end
new(taxa) click to toggle source

Return a singleton instance for any CYO.

Calls superclass method
# File lib/checking-you-out/inner_spirit.rb, line 79
def self.new(taxa)
  # Support IETF String argument to this method, e.g. ::CHECKING::YOU::OUT::new('application/octet-stream')
  return self.from_ietf_media_type(taxa) if taxa.is_a?(String)
  # Otherwise return the memoized CYO singleton of this type.
  self.all_night[
    taxa.is_a?(::CHECKING::YOU::IN) ? taxa : super(*taxa)
  ] ||= self.allocate.tap { |cyo| cyo.send(:initialize, *taxa) }
end

Public Instance Methods

add_aka(taxa) click to toggle source

Take an additional CYI, store it locally, and memoize it as an alias for this CYO.

# File lib/checking-you-out/inner_spirit.rb, line 143
def add_aka(taxa)
  taxa = taxa.is_a?(::CHECKING::YOU::IN) ? taxa : self.class.superclass.new(*taxa)
  ::CHECKING::YOU::INSTANCE_NEEDLEMAKER.call(:@aka, taxa, self)
  self.class.all_night[taxa] = self
end
add_child(child_cyo) click to toggle source

Take an additional CYO, store it locally as our child, and ask it to add ourselves as its parent.

# File lib/checking-you-out/inner_spirit.rb, line 164
def add_child(child_cyo)
  ::CHECKING::YOU::INSTANCE_NEEDLEMAKER.call(:@children, child_cyo, self)
  child_cyo.add_parent(self) unless child_cyo.parents&.include?(self)
end
add_parent(parent_cyo) click to toggle source

Take an additional CYO, store it locally as our parent, and ask it to add ourselves as its child.

# File lib/checking-you-out/inner_spirit.rb, line 158
def add_parent(parent_cyo)
  ::CHECKING::YOU::INSTANCE_NEEDLEMAKER.call(:@parents, parent_cyo, self)
  parent_cyo.add_child(self) unless parent_cyo.children&.include?(self)
end
add_pathname_fragment(fragment) click to toggle source

Add a new Postfix or Glob for a specific type.

# File lib/checking-you-out/inner_spirit.rb, line 122
def add_pathname_fragment(fragment)
  if fragment.start_with?(-'*.') and fragment.count(-?.) == 1 and fragment.count(-?*) == 1 then
    ::CHECKING::YOU::INSTANCE_NEEDLEMAKER.call(:@postfixes, fragment, self)
    ::CHECKING::YOU::CLASS_NEEDLEMAKER.call(:@after_forever, fragment, self)
  else
    ::CHECKING::YOU::INSTANCE_NEEDLEMAKER.call(:@globs, fragment, self)
    ::CHECKING::YOU::CLASS_NEEDLEMAKER.call(:@stick_around, fragment, self)
  end
end
adults_table() click to toggle source

Get a `Set` of this CYO and all of its parent CYOs, at minimum just `Set`.

# File lib/checking-you-out/inner_spirit.rb, line 170
def adults_table
  return case @parents
    when nil then Set[self]
    when self.class, self.class.superclass then Set[self, @parents]
    when ::Set then Set[self, *@parents]
  end
end
aka() click to toggle source

Get a `Set` of this CYO and all of its parent CYOs, at minimum just `Set`.

# File lib/checking-you-out/inner_spirit.rb, line 134
def aka
  return case @aka
    when nil then Set[self.in]
    when self.class, self.class.superclass then Set[self.in, @aka]
    when ::Set then Set[self.in, *@aka]
  end
end
family_tree() click to toggle source

Get a `Set` of this CYO and all parents and children, at minimum just `Set`.

# File lib/checking-you-out/inner_spirit.rb, line 188
def family_tree; self.kids_table | self.adults_table; end
in() click to toggle source
# File lib/checking-you-out/inner_spirit.rb, line 91
def in; self.class.all_night.key(self); end
kids_table() click to toggle source

Get a `Set` of this CYO and all of its child CYOs, at minimum just `Set`.

# File lib/checking-you-out/inner_spirit.rb, line 179
def kids_table
  return case @children
    when nil then Set[self]
    when self.class, self.class.superclass then Set[self, @children]
    when ::Set then Set[self, *@children]
  end
end
out() click to toggle source

Demote any CYO to a CYI that can be passed around in just 40 bytes. CYI has the opposites of these methods.

# File lib/checking-you-out/inner_spirit.rb, line 90
def out; self; end
remove_aka(taxa) click to toggle source

Forget a CYI alias of this Type. Capable of unsetting the “real” CYI as well if desired.

# File lib/checking-you-out/inner_spirit.rb, line 150
def remove_aka(taxa)
  taxa = taxa.is_a?(::CHECKING::YOU::IN) ? taxa : self.class.superclass.new(*taxa)
  self.class.all_night.delete(taxa) if self.class.all_night[taxa] === self
end