Class: MyTankInfo::TankReconciliationRecordCollection
- Inherits:
-
Object
- Object
- MyTankInfo::TankReconciliationRecordCollection
- Defined in:
- lib/my_tank_info/tank_reconciliation_record_collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#ended_at ⇒ Object
readonly
Returns the value of attribute ended_at.
-
#height_uom ⇒ Object
readonly
Returns the value of attribute height_uom.
-
#reconciliation_period ⇒ Object
readonly
Returns the value of attribute reconciliation_period.
-
#site_id ⇒ Object
readonly
Returns the value of attribute site_id.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#volume_uom ⇒ Object
readonly
Returns the value of attribute volume_uom.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, reconciliation_period:) ⇒ TankReconciliationRecordCollection
constructor
A new instance of TankReconciliationRecordCollection.
- #tanks ⇒ Object
Constructor Details
#initialize(data:, reconciliation_period:) ⇒ TankReconciliationRecordCollection
Returns a new instance of TankReconciliationRecordCollection.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 17 def initialize(data:, reconciliation_period:) @data = data @size = @data.size @reconciliation_period = reconciliation_period @site_id = @data.first&.site_id @started_at = @data.min_by(&:started_at)&.started_at @ended_at = @data.max_by(&:started_at)&.started_at @volume_uom = @data.first&.volume_uom @height_uom = @data.first&.height_uom end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def data @data end |
#ended_at ⇒ Object (readonly)
Returns the value of attribute ended_at.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def ended_at @ended_at end |
#height_uom ⇒ Object (readonly)
Returns the value of attribute height_uom.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def height_uom @height_uom end |
#reconciliation_period ⇒ Object (readonly)
Returns the value of attribute reconciliation_period.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def reconciliation_period @reconciliation_period end |
#site_id ⇒ Object (readonly)
Returns the value of attribute site_id.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def site_id @site_id end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def size @size end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def started_at @started_at end |
#volume_uom ⇒ Object (readonly)
Returns the value of attribute volume_uom.
5 6 7 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 5 def volume_uom @volume_uom end |
Class Method Details
.from_response(response, reconciliation_period:) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 8 def self.from_response(response, reconciliation_period:) body = response.body @collection = new( data: body.map { |attrs| TankReconciliationRecord.new(attrs) }, reconciliation_period: reconciliation_period ) end |
Instance Method Details
#tanks ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/my_tank_info/tank_reconciliation_record_collection.rb', line 30 def tanks @data.map { |record| records = @data.select { _1.tank_number == record.tank_number }.sort_by(&:started_at) summary = TankReconciliationRecordSummary.new( records, capacity: record.total_tanks_capacity, reconciliation_period: @reconciliation_period ) Tank.new( name: record.name, product_name: record.product_name, tank_number: record.tank_number, tank_numbers: record.tank_numbers, capacity: record.total_tanks_capacity, reconciliation_records: records, reconciliation_summary: summary, passed?: summary.passed?, failed?: summary.failed? ) }.uniq { |tank| tank.name } .sort_by(&:tank_number) end |