Sha256: c4bdb0c94a4030575f1b4ab6cf8406fe0214cb403785c9ea92cd4b4596a9eda2

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Rake
  module Funnel
    module Support
      class BinaryVersionReader
        class << self
          KNOWN_ATTRIBUTES = %i(company_name
                                file_description
                                file_version
                                legal_copyright
                                product_name
                                product_version
                                assembly_version).freeze
          SEPARATOR = "\0".freeze
          TERMINATOR = "\0" * 3

          def read_from(assembly)
            binary = File.binread(assembly)

            attributes = KNOWN_ATTRIBUTES.map do |attr|
              read_attribute(binary, attr)
            end

            hash = attributes.inject({}) do |memo, attr|
              memo.merge(attr)
            end

            VersionInfo.new(hash)
          end

          private

          def read_attribute(binary, attr)
            binary_attr = attr.pascalize.gsub(/(.)/) { |match| match + SEPARATOR }

            data = binary.match(/#{binary_attr}#{SEPARATOR}+(.*?)#{TERMINATOR}/)
            return {} if data.nil?

            { attr.to_s => data[1].gsub(/#{SEPARATOR}/, '') }
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake-funnel-0.24.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.23.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.22.3 lib/rake/funnel/support/binary_version_reader.rb