Class: Factbook::Comparisons

Inherits:
Object
  • Object
show all
Defined in:
lib/factbook-fields/comparisons.rb

Defined Under Namespace

Classes: Comparison

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comps) ⇒ Comparisons

Returns a new instance of Comparisons.



32
33
34
# File 'lib/factbook-fields/comparisons.rb', line 32

def initialize( comps )
  @comps = comps
end

Class Method Details

.read_csv(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/factbook-fields/comparisons.rb', line 11

def self.read_csv( path )

  rows = CsvHash.read( path )

  pp rows

  recs = []
  rows.each do |row|
    pp row
    rec = Comparison.new
    rec.num      = row['Num'].strip.to_i    ## remove leading n trailing whitespaces
    rec.category = row['Category'].strip
    rec.name     = row['Name'].strip

    pp rec
    recs << rec
  end

  new( recs )
end

Instance Method Details

#eachObject



38
39
40
# File 'lib/factbook-fields/comparisons.rb', line 38

def each
  @comps.each {|comp| yield( comp ) }
end

#sizeObject



36
# File 'lib/factbook-fields/comparisons.rb', line 36

def size() @comps.size; end

#to_aObject



42
43
44
# File 'lib/factbook-fields/comparisons.rb', line 42

def to_a
  @comps.collect {|comp| comp.num }   ## return array of nums   -- return something else - why? why not?
end