Class: NRB::BeerXML::RecordSet
- Inherits:
-
Object
- Object
- NRB::BeerXML::RecordSet
- Includes:
- Enumerable
- Defined in:
- lib/nrb/beerxml/record_set.rb
Defined Under Namespace
Classes: UnknownRecordTypeError
Instance Attribute Summary collapse
-
#record_type ⇒ Object
readonly
Returns the value of attribute record_type.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(record) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(record_type: nil) ⇒ RecordSet
constructor
A new instance of RecordSet.
- #record_count ⇒ Object
Constructor Details
#initialize(record_type: nil) ⇒ RecordSet
Returns a new instance of RecordSet.
26 27 28 29 30 |
# File 'lib/nrb/beerxml/record_set.rb', line 26 def initialize(record_type: nil) raise UnknownRecordTypeError.new("Don't know what to do with a #{record_type} record") unless valid_record_type?(record_type) @record_type = record_type @records = [] end |
Instance Attribute Details
#record_type ⇒ Object (readonly)
Returns the value of attribute record_type.
8 9 10 |
# File 'lib/nrb/beerxml/record_set.rb', line 8 def record_type @record_type end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
8 9 10 |
# File 'lib/nrb/beerxml/record_set.rb', line 8 def records @records end |
Class Method Details
.valid_record_types ⇒ Object
10 11 12 |
# File 'lib/nrb/beerxml/record_set.rb', line 10 def self.valid_record_types %i( equipment fermentable hop mash mash_step misc recipe style water yeast ) end |
Instance Method Details
#<<(record) ⇒ Object
15 16 17 18 |
# File 'lib/nrb/beerxml/record_set.rb', line 15 def <<(record) raise UnknownRecordTypeError.new("Can't add a #{record.record_type} to this set (only #{record_type}s)") unless valid_record_type?(record.record_type) @records << record end |
#each(&block) ⇒ Object
21 22 23 |
# File 'lib/nrb/beerxml/record_set.rb', line 21 def each(&block) @records.each &block end |
#record_count ⇒ Object
33 34 35 |
# File 'lib/nrb/beerxml/record_set.rb', line 33 def record_count @records.size end |