Class: H::Generator
- Inherits:
-
Object
- Object
- H::Generator
- Defined in:
- lib/h.rb
Constant Summary collapse
- CONF_PATH =
File.join(File.('~'), '.h')
Instance Method Summary collapse
-
#initialize(static_key = nil) ⇒ Generator
constructor
A new instance of Generator.
- #input(m, l = 44) ⇒ Object
- #prompt ⇒ Object
Constructor Details
#initialize(static_key = nil) ⇒ Generator
Returns a new instance of Generator.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/h.rb', line 8 def initialize(static_key = nil) @static_key = if static_key static_key else unless File.exists?(CONF_PATH) print "Creating #{CONF_PATH} file... " File.open(CONF_PATH, 'w') do |f| f.write('secret') end File.chmod(0600, CONF_PATH) puts "Done." end File.open(CONF_PATH).readlines.first.chomp end end |
Instance Method Details
#input(m, l = 44) ⇒ Object
32 33 34 35 36 |
# File 'lib/h.rb', line 32 def input(m, l = 44) m = m + @static_key d = cryptographic_hash(m) truncate d, l end |
#prompt ⇒ Object
28 29 30 |
# File 'lib/h.rb', line 28 def prompt input ask('Message: ') {|q| q.echo = '*' } end |