Module: Ppp

Defined in:
lib/ppp.rb,
lib/ppp/version.rb,
lib/ppp/card/base.rb

Defined Under Namespace

Modules: Card Classes: Generator

Constant Summary collapse

VERSION =
'1.0.1'
@@ALPHABETS =
{ :conservative => '!#%+23456789:=?@ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
:aggressive   => '!"#$%&\'()*+,-./23456789:;<=>?@ABCDEFGHJKLMNOPRSTUVWXYZ[\]^_abcdefghijkmnopqrstuvwxyz{|}~' }

Class Method Summary collapse

Class Method Details

.card(type, *args) ⇒ Object

Returns a Card of the given type.

Parameters:

  • type (Symbol)

    the type of card to return

  • args (Array)

    parameters to pass to the card’s constructor

Returns:

  • a Card of the given type

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
# File 'lib/ppp.rb', line 34

def card type, *args
  case type
  when :html  then return Card::Html.new  *args
  when :xml   then return Card::Xml.new   *args
  when :plain then return Card::Plain.new *args
  end
  raise ArgumentError.new( "%s is not a valid printer style." % style )
end

.code_generator(key, opts = {}) ⇒ Ppp::Generator

Returns with the given SHA-256 key.

Returns:



16
17
18
# File 'lib/ppp.rb', line 16

def code_generator key, opts={}
  Generator.new key, opts
end

.default_alphabetsHash{Symbol => String}

Returns the default alphabets.

Returns:

  • (Hash{Symbol => String})

    the default alphabets



44
45
46
# File 'lib/ppp.rb', line 44

def default_alphabets
  @@ALPHABETS
end

.key_from_string(str) ⇒ Object

Returns a SHA-256 digest of the given string.

Parameters:

  • str (String)

    some string to create a SHA-256 digest of

Returns:

  • a SHA-256 digest of the given string



22
23
24
# File 'lib/ppp.rb', line 22

def key_from_string str
  Digest::SHA256.new.update( str ).to_s
end

.random_keyObject

Returns a random SHA-256 key.

Returns:

  • a random SHA-256 key



27
28
29
# File 'lib/ppp.rb', line 27

def random_key
  Cppp.random_key
end