From 8b0b639434d5331a3354afb0bb62837ccec71cd4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 11 Aug 2013 14:29:55 -0400 Subject: [PATCH] add Book#find_account_by_full_name() --- lib/gnucash/book.rb | 4 ++++ spec/gnucash/book_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 spec/gnucash/book_spec.rb diff --git a/lib/gnucash/book.rb b/lib/gnucash/book.rb index 5e92b24..a7512c3 100644 --- a/lib/gnucash/book.rb +++ b/lib/gnucash/book.rb @@ -28,6 +28,10 @@ module Gnucash @accounts.find { |a| a.id == id } end + def find_account_by_full_name(full_name) + @accounts.find { |a| a.full_name == full_name } + end + private def build_accounts diff --git a/spec/gnucash/book_spec.rb b/spec/gnucash/book_spec.rb new file mode 100644 index 0000000..4d1f30d --- /dev/null +++ b/spec/gnucash/book_spec.rb @@ -0,0 +1,24 @@ +module Gnucash + describe Book do + before(:all) do + # just open the test file once + @subject = Gnucash.open("spec/books/sample.gnucash") + end + + it "records the date of the earliest transaction" do + @subject.start_date.should == "2007-01-01" + end + + it "records the date of the last transaction" do + @subject.end_date.should == "2012-12-28" + end + + it "lets you find an account by id" do + @subject.find_account_by_id("67e6e7daadc35716eb6152769373e974").name.should == "Savings Account" + end + + it "lets you find an account by full name" do + @subject.find_account_by_full_name("Assets::Current Assets::Savings Account").id.should == "67e6e7daadc35716eb6152769373e974" + end + end +end