find account by id; show account full name
This commit is contained in:
parent
2d42346541
commit
79219686aa
@ -1,9 +1,28 @@
|
|||||||
module Gnucash
|
module Gnucash
|
||||||
class Account
|
class Account
|
||||||
|
attr_accessor :name
|
||||||
|
attr_accessor :type
|
||||||
|
attr_accessor :id
|
||||||
|
|
||||||
def initialize(book, node)
|
def initialize(book, node)
|
||||||
|
@book = book
|
||||||
@node = node
|
@node = node
|
||||||
@name = node.xpath('act:name').text
|
@name = node.xpath('act:name').text
|
||||||
@type = node.xpath('act:type').text
|
@type = node.xpath('act:type').text
|
||||||
|
@id = node.xpath('act:id').text
|
||||||
|
@parent_id = node.xpath('act:parent').text
|
||||||
|
@parent_id = nil if @parent_id == ""
|
||||||
|
end
|
||||||
|
|
||||||
|
def full_name
|
||||||
|
prefix = ""
|
||||||
|
if @parent_id
|
||||||
|
parent = @book.find_account_by_id(@parent_id)
|
||||||
|
if parent and parent.type != 'ROOT'
|
||||||
|
prefix = parent.full_name + "::"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
prefix + name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,10 @@ module Gnucash
|
|||||||
build_accounts
|
build_accounts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_account_by_id(id)
|
||||||
|
@accounts.find { |a| a.id == id }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def build_accounts
|
def build_accounts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user