Class: MusicMetadataScore::Isrc

Inherits:
Object
  • Object
show all
Defined in:
lib/music_metadata_score/isrc.rb

Class Method Summary collapse

Class Method Details

.is_valid?(isrc) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/music_metadata_score/isrc.rb', line 4

def self.is_valid?(isrc)
	isrc = MusicMetadataScore::Isrc.strip_isrc(isrc)
	if MusicMetadataScore::Isrc.valid_length?(isrc) && MusicMetadataScore::Isrc.valid_country_code?(isrc[0..1]) && MusicMetadataScore::Isrc.valid_numbers?(isrc[5..11])
		true
	else
		false
	end
end

.strip_isrc(isrc) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/music_metadata_score/isrc.rb', line 22

def self.strip_isrc(isrc)
	if isrc
		isrc.strip!
		isrc.tr!('^A-Za-z0-9', '')
		isrc.upcase!
	end
	return isrc
end

.valid_country_code?(code) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/music_metadata_score/isrc.rb', line 31

def self.valid_country_code?(code)
	if code.length == 2 && code[/[a-zA-Z]+/] == code
		true
	else
		false
	end
end

.valid_isrc_or_nil(isrc) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/music_metadata_score/isrc.rb', line 48

def self.valid_isrc_or_nil(isrc)
	if MusicMetadataScore::Isrc.is_valid?(isrc)
		MusicMetadataScore::Isrc.strip_isrc(isrc)
	else
		nil
	end
end

.valid_length?(isrc) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/music_metadata_score/isrc.rb', line 13

def self.valid_length?(isrc)
	length = MusicMetadataScore::Isrc.strip_isrc(isrc).length rescue 0
	if length != 12
		false
	else
		true
	end
end

.valid_numbers?(numbers) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/music_metadata_score/isrc.rb', line 39

def self.valid_numbers?(numbers)
	number = Integer(numbers) rescue false
	if numbers.to_s.length == 7 && number
		true
	else
		false
	end
end