Class: Factbook::Category

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/factbook-fields/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Category

Returns a new instance of Category.



10
11
12
13
# File 'lib/factbook-fields/category.rb', line 10

def initialize( title )
  @title  = title
  @fields = {}
end

Instance Attribute Details

#titleObject (readonly)

use name instead of title - why? why not?



8
9
10
# File 'lib/factbook-fields/category.rb', line 8

def title
  @title
end

Instance Method Details

#[](key) ⇒ Object

convenience shortcut



21
22
23
# File 'lib/factbook-fields/category.rb', line 21

def [](key)  ### convenience shortcut
  @fields[ key ]
end

#add(field) ⇒ Object Also known as: <<



15
16
17
# File 'lib/factbook-fields/category.rb', line 15

def add( field )
  @fields[ field.title ] = field
end

#dataObject

convert to hash



29
30
31
32
33
34
35
36
37
# File 'lib/factbook-fields/category.rb', line 29

def data   ## convert to hash
  ## todo/fix: how to know when to rebuild?
  ##   for now @data MUST be reset to nil manually
  data = {}
  @fields.each do |_,field|
    data[ field.title ] = field.data
  end
  data
end

#sizeObject



25
# File 'lib/factbook-fields/category.rb', line 25

def size()   @fields.size; end