Class: TaxonReporter::Taxon
- Inherits:
-
Object
- Object
- TaxonReporter::Taxon
- Defined in:
- lib/taxon_reporter/taxon.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #add_field(field) ⇒ Object
- #add_record(record) ⇒ Object
- #add_values(field, values) ⇒ Object
- #fields ⇒ Object
-
#initialize(records = []) ⇒ Taxon
constructor
A new instance of Taxon.
- #values(field) ⇒ Object
Constructor Details
#initialize(records = []) ⇒ Taxon
Returns a new instance of Taxon.
7 8 9 10 11 12 |
# File 'lib/taxon_reporter/taxon.rb', line 7 def initialize(records=[]) @records = [] @fields = {} @values = {} records.each {|r| add_record(r)} end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
5 6 7 |
# File 'lib/taxon_reporter/taxon.rb', line 5 def records @records end |
Instance Method Details
#add_field(field) ⇒ Object
33 34 35 36 |
# File 'lib/taxon_reporter/taxon.rb', line 33 def add_field(field) key = field.id @fields[key] = field unless @fields.member?(key) end |
#add_record(record) ⇒ Object
23 24 25 26 |
# File 'lib/taxon_reporter/taxon.rb', line 23 def add_record(record) @records.push(record) add_values(record.field, record.values) end |
#add_values(field, values) ⇒ Object
28 29 30 31 |
# File 'lib/taxon_reporter/taxon.rb', line 28 def add_values(field, values) add_field(field) @values[field.id] = field.merge_values(@values[field.id], values) end |
#fields ⇒ Object
14 |
# File 'lib/taxon_reporter/taxon.rb', line 14 def fields; @fields.values; end |
#values(field) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/taxon_reporter/taxon.rb', line 15 def values(field) if field.is_a?(TaxonReporter::Field) @values[field.id] elsif field.is_a?(String) @values[field] end end |