Class: Qiflib::Category

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

Overview

Instances of this class represent a catgory parsed within the !Type:Cat section of a qif file. The qiflib gem only captures the category name, and not the other fields.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n = 0) ⇒ Category

Constructor. The given n arg is an integer id value; defaults to 0.



23
24
25
# File 'lib/qiflib_category.rb', line 23

def initialize(n=0)
  @id, @name = 0, "#{n}".strip.downcase
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/qiflib_category.rb', line 10

def id
  @id
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/qiflib_category.rb', line 11

def name
  @name
end

Class Method Details

.csv_headerObject

Return the CSV header row.



15
16
17
18
19
# File 'lib/qiflib_category.rb', line 15

def self.csv_header
  CSV.generate do | csv |
    csv << Qiflib::csv_category_field_names
  end 
end

Instance Method Details

#as_array(idx = 0) ⇒ Object

Return this instance an 2-element array; id and name.



37
38
39
40
41
42
# File 'lib/qiflib_category.rb', line 37

def as_array(idx=0)
  array = []
  array << idx + 1
  array << name
  array
end

#to_csv(idx = 0) ⇒ Object

Return this instance a CSV row.



29
30
31
32
33
# File 'lib/qiflib_category.rb', line 29

def to_csv(idx=0)
  CSV.generate do | csv |
    csv << as_array(idx)
  end 
end