Module: PolypassNaturalLanguage

Included in:
Polypass::NaturalLanguage
Defined in:
lib/polypass/natural_language.rb

Overview

Polypass::NaturalLanguage Class methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#language_dataObject

Returns the value of attribute language_data.



5
6
7
# File 'lib/polypass/natural_language.rb', line 5

def language_data
  @language_data
end

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/polypass/natural_language.rb', line 21

def create
  language = init_language_randomizer
  case @output_type
  when 'stdout'
    language.sentence + random_element(random_sample_set('alphanumeric', @length))
  when 'json'
    output_json({ 'password' => language.sentence + random_element(random_sample_set('alphanumeric', @length)) })
  when 'yaml'
    output_yaml({ 'password' => language.sentence + random_element(random_sample_set('alphanumeric', @length)) })
  end
end

#init_language_randomizerObject



12
13
14
15
16
17
18
19
# File 'lib/polypass/natural_language.rb', line 12

def init_language_randomizer
  return LiterateRandomizer.create(
    {
      source_material_file: random_element(@language_data),
      randomizer:  SecureRandom.random_number(Random.new_seed)
    }
  )
end

#initialize(length = 32, output_type = 'stdout') ⇒ Object



7
8
9
10
# File 'lib/polypass/natural_language.rb', line 7

def initialize(length = 32, output_type = 'stdout')
  super(length, output_type)
  @language_data = Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data')) + '/*.txt')
end