class AEMO::NMI::Allocation
AEMO::NMI::Allocation
-
@author Joel Courtney @author Stuart Auld @abstract An abstraction of
NMI
Allocation
groups that kind of representsnetworks but not always.
@since 0.3.0
@attr [Array<Regexp>]
exclude_nmi_patterns
@attr [String]friendly_title
@attr [String] identifier @attr [Array<Regexp>]include_nmi_patterns
@attr [AEMO::Region] region @attr [String] title @attr [Symbol] type
Constants
Attributes
Public Class Methods
Return all the NMI
allocations
@return [Array<AEMO::NMI::Allocation>]
# File lib/aemo/nmi/allocation.rb, line 399 def all ALLOCATIONS.map do |a| new(a.fetch(:title), a.fetch(:type), a) end end
Enumerable support
@return [Enumerator]
# File lib/aemo/nmi/allocation.rb, line 408 def each(&block) all.each(&block) end
Finds the Allocation
that encompasses a given NMI
@param [string] nmi @return [AEMO::NMI::Allocation]
# File lib/aemo/nmi/allocation.rb, line 416 def find_by_nmi(nmi) each do |allocation| allocation.exclude_nmi_patterns.each do |pattern| next if nmi.match(pattern) end allocation.include_nmi_patterns.each do |pattern| return allocation if nmi.match(pattern) end end nil end
Initialises an {AEMO::NMI::Allocation}
@param [String] title @param [String] type @param [Hash] opts @option opts [String] :identifier @option opts [String] :friendly_title @option opts [Array<Regexp>] :exclude_nmi_patterns @option opts [Array<Regexp>] :include_nmi_patterns @option opts [String] :region @return [AEMO::NMI::Allocation]
# File lib/aemo/nmi/allocation.rb, line 440 def initialize(title, type, opts = {}) @title = title @type = parse_allocation_type(type) @identifier = opts.fetch(:participant_id, title.upcase) @friendly_title = opts.fetch(:friendly_title, title) @exclude_nmi_patterns = opts.fetch(:excludes, []) @include_nmi_patterns = opts.fetch(:includes, []) @region = AEMO::Region.new(opts.fetch(:region)) if opts.dig(:region) end
Private Instance Methods
Private method to parse an
@param [#to_sym] type @raise [AEMO::InvalidNMIAllocationType] @return [Symbol]
# File lib/aemo/nmi/allocation.rb, line 457 def parse_allocation_type(type) type_sym = type.to_sym unless SUPPORTED_TYPES.include?(type_sym) raise AEMO::InvalidNMIAllocationType end type_sym rescue NoMethodError raise AEMO::InvalidNMIAllocationType end