Sha256: e91d4d0fc1da20324053198b1a6b6462ce018b9164206f4902e630328d6f4fcb
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
# # Copyright (c) 2006-2012 Hal Brodigan (postmodern.mod3 at gmail.com) # # This file is part of Ronin Support. # # Ronin Support is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ronin Support is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>. # require 'ronin/binary/template' class Float # # Packs the Float into a String. # # @param [String, Symbol] argument # The `Array#pack` String code or {Ronin::Binary::Template} type. # # @return [String] # The packed float. # # @raise [ArgumentError] # The given Symbol could not be found in # {Ronin::Binary::Template::FLOAT_TYPES}. # # @example using `Array#pack` template: # 0.42.pack('F') # # => =\n\xD7>" # # @example using {Ronin::Binary::Template} types: # 0x42.pack(:float_be) # # => ">\xD7\n=" # # @see http://rubydoc.info/stdlib/core/Array:pack # @see Ronin::Binary::Template # # @since 0.5.0 # # @api public # def pack(argument) case argument when String [self].pack(argument) else unless Ronin::Binary::Template::FLOAT_TYPES.include?(argument) raise(ArgumentError,"unsupported integer type: #{argument}") end [self].pack(Ronin::Binary::Template::TYPES[argument]) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ronin-support-0.5.1 | lib/ronin/formatting/extensions/binary/float.rb |