Class: GDV::Model::Transmission

Inherits:
Object
  • Object
show all
Defined in:
lib/gdv/model/transmission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Transmission


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gdv/model/transmission.rb', line 7

def initialize(filename)
    reader = GDV::Format::Reader.new(filename)
    @packages = []
    reader.unshift reader.match!(:sid => VORSATZ)
    @contracts_count = 0
    while reader.match?(:sid => VORSATZ)
        @packages << Package::parse(reader)
        @packages.last.filename = filename
        @contracts_count += @packages.last.contracts.size
    end
    index = Hash.new(0)
    self.each_contract { |p, c| index["#{c.vunr}##{c.vsnr}"] += 1 }
    @unique_contracts_count = index.keys.size
end

Instance Attribute Details

#contracts_countObject (readonly)

Returns the value of attribute contracts_count


5
6
7
# File 'lib/gdv/model/transmission.rb', line 5

def contracts_count
  @contracts_count
end

#packagesObject (readonly)

Returns the value of attribute packages


5
6
7
# File 'lib/gdv/model/transmission.rb', line 5

def packages
  @packages
end

#unique_contracts_countObject (readonly)

Returns the value of attribute unique_contracts_count


5
6
7
# File 'lib/gdv/model/transmission.rb', line 5

def unique_contracts_count
  @unique_contracts_count
end

Instance Method Details

#each_contract(&block) ⇒ Object

Calls block once for each contract in this transmission, passing the package to which the contract belongs and the contract.


25
26
27
28
29
30
31
# File 'lib/gdv/model/transmission.rb', line 25

def each_contract(&block)
    @packages.each do |pkg|
        pkg.contracts.each do |contract|
            yield(pkg, contract)
        end
    end
end