Skip to content

Commit

Permalink
Revised pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
jufemaiz committed May 15, 2016
1 parent b92acd4 commit 0cace96
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
13 changes: 7 additions & 6 deletions lib/aemo/nmi.rb
Expand Up @@ -429,19 +429,20 @@ class NMI
#
# @param nmi [String] the National Meter Identifier (NMI)
# @param options [Hash] a hash of options
# @option options [Hash] :msats_detail MSATS details as per #parse_msats_detail requirements
# @return [AEMO::NMI] an instance of AEMO::NMI is returned
def initialize(nmi, options = {})
raise ArgumentError, 'NMI is not a string' unless nmi.is_a?(String)
raise ArgumentError, 'NMI is not 10 characters' unless nmi.length == 10
raise ArgumentError, 'NMI is not constructed with valid characters' unless AEMO::NMI.valid_nmi?(nmi)

@nmi = nmi
@meters = []
@roles = {}
@data_streams = []
@msats_detail = options['msats_detail']
@nmi = nmi
@meters = []
@roles = {}
@data_streams = []
@msats_detail = options[:msats_detail]

parse_msats_detail unless options['msats_detail'].nil?
parse_msats_detail unless @msats_detail.nil?
end

# A function to validate the instance's nmi value
Expand Down
54 changes: 34 additions & 20 deletions spec/lib/aemo/nmi_spec.rb
Expand Up @@ -27,31 +27,35 @@
# CLASS METHODS
# ---
describe '.valid_nmi?(nmi)' do
it 'should validate nmi' do
json.each do |nmi|
expect(AEMO::NMI.valid_nmi?(nmi['nmi'])).to eq(true)
context 'valid' do
it 'should validate nmi' do
json.each do |nmi|
expect(AEMO::NMI.valid_nmi?(nmi['nmi'])).to eq(true)
end
end
end
it 'should invalidate' do
expect(AEMO::NMI.valid_nmi?('OOOOOOOOOO')).to eq(false)
end
it 'should invalidate' do
expect(AEMO::NMI.valid_nmi?('NM100')).to eq(false)
end
it 'should invalidate' do
expect { AEMO::NMI.valid_nmi? }.to raise_error(ArgumentError)
context 'invalid' do
it 'should invalidate' do
expect(AEMO::NMI.valid_nmi?('OOOOOOOOOO')).to eq(false)
end
it 'should invalidate' do
expect(AEMO::NMI.valid_nmi?('NM100')).to eq(false)
end
it 'should invalidate' do
expect { AEMO::NMI.valid_nmi? }.to raise_error(ArgumentError)
end
end
end

describe '.self.valid_checksum?(nmi, checksum)' do
describe '.valid_checksum?(nmi, checksum)' do
it 'should validate valid nmi and checksums' do
json.each do |nmi|
expect(AEMO::NMI.valid_checksum?(nmi['nmi'], nmi['checksum'])).to eq(true)
end
end
end

describe '.self.network?(nmi)' do
describe '.network?(nmi)' do
it 'should return a network for an allocated NMI' do
network = AEMO::NMI.network('NCCCC00000')
expect(network.to_a[0].last[:title]).to eq('Ausgrid')
Expand All @@ -66,14 +70,24 @@
# INSTANCE METHODS
# ---
describe '#initialize' do
it 'should raise an ArgumentError error' do
expect { AEMO::NMI.new('OOOOOOOOOO') }.to raise_error(ArgumentError)
end
it 'should raise an ArgumentError error' do
expect { AEMO::NMI.new('NM100') }.to raise_error(ArgumentError)
context 'valid' do
it 'should return a valid NMI' do
expect(AEMO::NMI.new('NM10000000')).to be_a(AEMO::NMI)
end
it 'should return a valid NMI with MSATS' do
expect(AEMO::NMI.new('NM10000000', { msats_detail: {} })).to be_a(AEMO::NMI)
end
end
it 'should raise an ArgumentError error' do
expect { AEMO::NMI.new }.to raise_error(ArgumentError)
context 'invalid' do
it 'should raise an ArgumentError error' do
expect { AEMO::NMI.new('OOOOOOOOOO') }.to raise_error(ArgumentError)
end
it 'should raise an ArgumentError error' do
expect { AEMO::NMI.new('NM100') }.to raise_error(ArgumentError)
end
it 'should raise an ArgumentError error' do
expect { AEMO::NMI.new }.to raise_error(ArgumentError)
end
end
end
describe '#valid_nmi?' do
Expand Down

0 comments on commit 0cace96

Please sign in to comment.