Class: TalcOTP
- Inherits:
-
Object
- Object
- TalcOTP
- Defined in:
- lib/talcotp.rb
Instance Method Summary collapse
- #[](account_name) ⇒ Object
- #all_codes_string ⇒ Object
-
#initialize(file) ⇒ TalcOTP
constructor
A new instance of TalcOTP.
Constructor Details
#initialize(file) ⇒ TalcOTP
Returns a new instance of TalcOTP.
5 6 7 8 9 10 11 12 13 |
# File 'lib/talcotp.rb', line 5 def initialize file file = File.file?(file) ? File.read(file) : '' begin @accounts = JSON.parse(file) rescue JSON::ParserError @accounts = {} end end |
Instance Method Details
#[](account_name) ⇒ Object
26 27 28 29 |
# File 'lib/talcotp.rb', line 26 def [](account_name) account = @accounts.find { |account| account["label"] == account_name } return auth_code(account) end |
#all_codes_string ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/talcotp.rb', line 15 def all_codes_string output = '' @accounts.each do |account| account_auth_code = auth_code(account) output += "#{account['label']}: #{account_auth_code}\n" end output end |