Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Latest commit

 

History

History
69 lines (44 loc) · 1.32 KB

README.rdoc

File metadata and controls

69 lines (44 loc) · 1.32 KB

integer-base

Description

Your format comes into positional numeral systems.

Feautures

  • You can build upper 36 basenumbers so easily

  • And get own formats so easily too :)

    e.g.

    • 0 1 -> 0 a

    • 0 1 2 3 4 5 6 7 8 9 -> a b c d e f g h i j

Usage

  • Setup

    require 'integer/base'
    
  • Basic

    Integer::Base.parse '10', %w[0 1]   #=> 2
    
  • Extend Ruby’s Interface

    require 'integer/base/ext'
    
  • to_i

    'a'.to_i   ['0', *'A'..'I']        #=> 1
    'a0'.to_i  ['0', *'A'..'I']        #=> 10
    'aib'.to_i ['0', *'A'..'I']        #=> 192
    
  • to_s

    192.to_s   ['0', *'A'..'I']        #=> 'aib'
    
  • Already defined useful chars

    '10'.to_i Integer::Base::STANDARD_CHARS[36].last         #=> :Z
    '10'.to_i Integer::Base::STANDARD_CHARS[:BINARY].last    #=> :"1"
    
  • Get own formats

    'a'.to_i  %w[0 a]                  #=> 1
    'a0'.to_i %w[0 a]                  #=> 2
    
  • Upper 36 basenumbers

    '1!'.to_i([*Integer::Base::STANDARD_CHARS[36], '!']) #=> 73
    

Requirements

  • Ruby 1.9.2 or later

    Focusing

    • 1.9.3-p194

    • 1.9.2-p290

Installation

  • gem install integer-base

License

The MIT X11 License

Copyright © 2011 Kenichi Kamiya

See the file LICENSE for further details.