Sha256: f8cfc1432f5661a391cfc856b778a5f6038cc40a9c280637f4aa99d5440417a7

Contents?: true

Size: 1.95 KB

Versions: 19

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

module AEMO
  # AEMO::Region
  #
  # @author Joel Courtney
  # @abstract
  # @since 0.1.0
  class Region
    # Regions under juristiction
    REGIONS = {
      'ACT' => 'Australian Capital Territory',
      'NSW' => 'New South Wales',
      'QLD' => 'Queensland',
      'SA'  => 'South Australia',
      'TAS' => 'Tasmania',
      'VIC' => 'Victoria',
      'NT'  => 'Northern Territory',
      'WA'  => 'Western Australia'
    }.freeze

    attr_accessor :region
    attr_reader :aemo_market_node

    class << self
      def all
        REGIONS.keys.map { |k| AEMO::Region.new(k) }
      end
    end

    # Create a new instance of AEMO::Region
    #
    # @param [String] region State
    # @return [self]
    def initialize(region)
      raise ArgumentError, "Region '#{region}' is not valid." unless valid_region?(region)
      @region = region.upcase
      @full_name = REGIONS[@region]
      @current_trading = []
      @current_dispatch = []
      @aemo_market_node = if %w[NSW QLD SA TAS VIC].include?(@region)
                            AEMO::Market::Node.new(region)
                          elsif @region == 'ACT'
                            AEMO::Market::Node.new('NSW')
                          end
    end

    # Abbreviation method
    #
    # @return [String]
    def abbr
      @region
    end

    # @return [String]
    def to_s
      @region
    end

    # @return [String]
    def fullname
      REGIONS[@region]
    end

    # Return the current dispatch data
    #
    # @return [Array<AEMO::Market::Interval>]
    def current_dispatch
      @aemo_market_node.current_dispatch
    end

    # Return the current trading data
    #
    # @return [Array<AEMO::Market::Interval>]
    def current_trading
      @aemo_market_node.current_trading
    end

    protected

    # Validates a region
    #
    # @param [String] region
    # @return [Boolean]
    def valid_region?(region)
      REGIONS.keys.include?(region.upcase)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
aemo-0.5.1 lib/aemo/region.rb
aemo-0.5.0 lib/aemo/region.rb
aemo-0.4.1 lib/aemo/region.rb
aemo-0.4.0 lib/aemo/region.rb
aemo-0.3.6 lib/aemo/region.rb
aemo-0.3.5 lib/aemo/region.rb
aemo-0.3.4 lib/aemo/region.rb
aemo-0.3.3 lib/aemo/region.rb
aemo-0.3.2 lib/aemo/region.rb
aemo-0.3.1 lib/aemo/region.rb
aemo-0.3.0 lib/aemo/region.rb
aemo-0.3.0.pre.rc1 lib/aemo/region.rb
aemo-0.2.1 lib/aemo/region.rb
aemo-0.2.0 lib/aemo/region.rb
aemo-0.1.45 lib/aemo/region.rb
aemo-0.1.44 lib/aemo/region.rb
aemo-0.1.42 lib/aemo/region.rb
aemo-0.1.41 lib/aemo/region.rb
aemo-0.1.40 lib/aemo/region.rb