Class: Oplop
- Inherits:
-
Object
- Object
- Oplop
- Defined in:
- lib/oplop.rb,
lib/oplop/cli.rb,
lib/oplop/version.rb
Defined Under Namespace
Modules: Cli
Constant Summary collapse
- LEGACY_LENGTH =
8
- DEFAULT_LENGTH =
16
- VERSION =
"2.0.0"
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#master ⇒ Object
readonly
Returns the value of attribute master.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Oplop
constructor
A new instance of Oplop.
- #master_label ⇒ Object
- #password ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Oplop
Returns a new instance of Oplop.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/oplop.rb', line 14 def initialize(args={}) @master = args[:master] @label = args[:label] @length = args[:length] || DEFAULT_LENGTH if @label =~ /^([0-9]*)?\*/ (@length, @label) = @label.split('*') @length = length.to_i @length = LEGACY_LENGTH if length <= 0 end end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'lib/oplop.rb', line 5 def label @label end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
5 6 7 |
# File 'lib/oplop.rb', line 5 def length @length end |
#master ⇒ Object (readonly)
Returns the value of attribute master.
5 6 7 |
# File 'lib/oplop.rb', line 5 def master @master end |
Class Method Details
.password(args = {}) ⇒ Object
10 11 12 |
# File 'lib/oplop.rb', line 10 def self.password(args={}) self.new(args).password end |
Instance Method Details
#master_label ⇒ Object
26 27 28 |
# File 'lib/oplop.rb', line 26 def master_label @master_label ||= '%s%s' % [ master, label ] end |
#password ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/oplop.rb', line 30 def password password = Base64.urlsafe_encode64(Digest::MD5.digest(master_label)) if password.respond_to?(:encode) password = password.encode('UTF-8') end if m = password.match(/\d+/) password = '%s%s' % [ m[0], password ] if (m.begin(0) >= length) else password = '1%s' % password end password[0,length] end |