Moon

Introducing Chars 0.1.0

2009 / 03 / 17 — alpha, ascii, case, char, chars, code, generate, git, github, hex, hexadecimal, lower, numeric, octal, random, ruby, rubygem, text, upper

Yesterday I released the first version of Chars. Chars is a Ruby library for working with character sets, generating random text and determining whether Strings or Integers belong to specific sets. Originally, Chars was part of the Ronin code-base, but was split-out in order to keep Ronin small and to promote code-reuse. So without further ado, here's some examples of what Chars can do:

  • Determine whether a byte belongs to a character set:
    0x41.alpha?
    # => true
  • Determine whether a String belongs to a character set:
    "hello;".printable?
    # => true
  • Find all sub-strings that belong to a character set within a String:
    ls = File.read('/bin/ls')
    Chars.printable.strings_in(ls)
    # => ["/lib64/ld-linux-x86-64.so.2", "KIq/", "5J~!", "%L~!", ...]
  • Return a random character from the set of all characters:
    Chars.all.random_char
    # => "\x94"
  • Return a random Array of characters from the alpha-numeric character set:
    Chars.alpha_numeric.random_array(10)
    # => ["Q", "N", "S", "4", "x", "z", "3", "M", "F", "F"]
  • Return a random String from the set of all characters:
    Chars.all.random_string(10)
    # => "\xc2h\xad\xccm7\x1e6J\x13"
  • Return a random String with a random length between 5 and 10, from the set of space characters:
    Chars.space.random_string(5..10)
    # => "\r\v\n\t\n\f"

You can install Chars as a rubygem using the following command:

$ sudo gem install chars

If you want to hack on Chars, the code-base is available on GitHub.

Comments

blog comments powered by Disqus