Class: Factbook::Category
- Inherits:
-
Object
- Object
- Factbook::Category
- Includes:
- LogUtils::Logging
- Defined in:
- lib/factbook-fields/category.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
use name instead of title - why? why not?.
Instance Method Summary collapse
-
#[](key) ⇒ Object
convenience shortcut.
- #add(field) ⇒ Object (also: #<<)
-
#data ⇒ Object
convert to hash.
-
#initialize(title) ⇒ Category
constructor
A new instance of Category.
- #size ⇒ Object
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
#title ⇒ Object (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 |
#data ⇒ Object
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 |
#size ⇒ Object
25 |
# File 'lib/factbook-fields/category.rb', line 25 def size() @fields.size; end |