Sha256: ad381ea4d945f6e41d58d8485884872cd88b5273d438cf0343ecb603706028fc

Contents?: true

Size: 1.34 KB

Versions: 44

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'ehbrs/executables'
require 'ehbrs/vg/wii/wit/parsers/info'

module Ehbrs
  module Vg
    module Wii
      module Wit
        class ImageFormat
          class << self
            SECTION_NAME_PATTERN = /\A#{::Regexp.quote('IMAGE-FORMAT:')}(.+)\z/.freeze

            enable_simple_cache

            def by_name(name)
              all.find { |i| i.name.downcase == name.to_s.downcase } ||
                raise(::ArgumentError, "Image not found with name \"#{name.to_s.downcase}\"" \
                  " (Available: #{all.map(&:name).join(', ')})")
            end

            private

            def all_uncached
              ::Ehbrs::Vg::Wii::Wit::Parsers::Info.new(info_output).images.map do |_label, data|
                new(
                  *%w[name info option].map { |k| data.fetch(k) },
                  *%w[extensions attributes].map { |k| data.fetch(k).to_s.split(/\s+/) }
                )
              end
            end

            def info_output
              ::Ehbrs::Executables.wit.command
                                  .append(%w[info image-format --sections])
                                  .execute!
            end
          end

          common_constructor :name, :description, :option, :extensions, :attributes
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
ehbrs-tools-0.35.1 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.35.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.34.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.33.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.32.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.31.1 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.31.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.30.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.29.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.28.3 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.28.2 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.28.1 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.28.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.27.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.26.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.25.1 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.25.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.24.0 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.23.1 lib/ehbrs/vg/wii/wit/image_format.rb
ehbrs-tools-0.23.0 lib/ehbrs/vg/wii/wit/image_format.rb