class AEMO::NMI::Allocation

AEMO::NMI::Allocation

@author Joel Courtney @author Stuart Auld @abstract An abstraction of NMI Allocation groups that kind of represents

networks 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

ALLOCATIONS

NMI_ALLOCATIONS as per AEMO Documentation at

https://www.aemo.com.au/-/media/Files/Electricity/NEM/Retail_and_Metering/Metering-Procedures/NMI-Allocation-List.pdf
Last updated 2017-08-01
SUPPORTED_TYPES

NMI Allocations are only for Electricity and Gas metering

Attributes

exclude_nmi_patterns[RW]
friendly_title[RW]
identifier[RW]
include_nmi_patterns[RW]
region[RW]
state[RW]
state=[RW]
title[RW]
type[RW]

Public Class Methods

all() click to toggle source

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
each(&block) click to toggle source

Enumerable support

@return [Enumerator]

# File lib/aemo/nmi/allocation.rb, line 408
def each(&block)
  all.each(&block)
end
find_by_nmi(nmi) click to toggle source

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
new(title, type, opts = {}) click to toggle source

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

parse_allocation_type(type) click to toggle source

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