Class: Athena::Record
- Inherits:
-
Object
- Object
- Athena::Record
- Defined in:
- lib/athena/record.rb
Defined Under Namespace
Classes: NoRecordError
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #fill(field, config) ⇒ Object
-
#initialize(id = nil, block = nil, add = !block)) ⇒ Record
constructor
A new instance of Record.
- #to(format) ⇒ Object
- #update(element, data, field_config = nil) ⇒ Object
Constructor Details
#initialize(id = nil, block = nil, add = !block)) ⇒ Record
Returns a new instance of Record.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/athena/record.rb', line 58 def initialize(id = nil, block = nil, add = !block) @id, @block, @struct = id || object_id.map_positive, block, {} add_record if add if block_given? begin yield self ensure close end end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
56 57 58 |
# File 'lib/athena/record.rb', line 56 def block @block end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
56 57 58 |
# File 'lib/athena/record.rb', line 56 def id @id end |
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
56 57 58 |
# File 'lib/athena/record.rb', line 56 def struct @struct end |
Class Method Details
.[](field = nil, config = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/athena/record.rb', line 46 def [](field = nil, config = nil) record = records.last raise NoRecordError unless record record.fill(field, config) if field && config record end |
.records ⇒ Object
42 43 44 |
# File 'lib/athena/record.rb', line 42 def records @records end |
Instance Method Details
#close ⇒ Object
81 82 83 |
# File 'lib/athena/record.rb', line 81 def close block ? block[self] : self end |
#fill(field, config) ⇒ Object
72 73 74 |
# File 'lib/athena/record.rb', line 72 def fill(field, config) struct[field] ||= config.merge(:values => Hash.new { |h, k| h[k] = [] }) end |
#to(format) ⇒ Object
85 86 87 |
# File 'lib/athena/record.rb', line 85 def to(format) Formats[:out, format].convert(self) end |
#update(element, data, field_config = nil) ⇒ Object
76 77 78 79 |
# File 'lib/athena/record.rb', line 76 def update(element, data, field_config = nil) field_config.each { |field, config| fill(field, config) } if field_config struct.each_key { |field| struct[field][:values][element] << data } end |