Class: XeroCLI::AccountsStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/xero_cli/accounts_storage.rb

Constant Summary collapse

JSON_FILE =
'accounts_storage.json'.freeze

Class Method Summary collapse

Class Method Details

.find_account_code_by_name(name) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/xero_cli/accounts_storage.rb', line 11

def self.(name)
  file = File.read(JSON_FILE)
  data_hash = JSON.parse(file)
  data_hash.find { |element| element['name'] == name }['code']
rescue StandardError
  raise Exception, 'Wrong category name'
end

.set(accounts) ⇒ Object



5
6
7
8
9
# File 'lib/xero_cli/accounts_storage.rb', line 5

def self.set(accounts)
  File.open(JSON_FILE, 'w+') do |file|
    file.write(accounts.to_json)
  end
end