Class: AudioInfo::Tipo

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

Overview

Recolección de información, a partir del tipo de archivo

Direct Known Subclasses

Ape, Audiofile, FileName, Flac, Mp3, Ogg, Virtual

Constant Summary collapse

TAGS =
['title','artist','tracknumber','album','year']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sFile) ⇒ Tipo

  • sFile: Nombre del archivo



112
113
114
115
116
117
# File 'lib/audioinfo.rb', line 112

def initialize(sFile)
	@sFile=sFile
	@size=File.stat(@sFile).size
	parse
	#@[email protected]_utf8
end

Instance Attribute Details

#albumObject

Returns the value of attribute album.



103
104
105
# File 'lib/audioinfo.rb', line 103

def album
  @album
end

#artistObject

Returns the value of attribute artist.



103
104
105
# File 'lib/audioinfo.rb', line 103

def artist
  @artist
end

#bits_per_sampleObject

Returns the value of attribute bits_per_sample.



103
104
105
# File 'lib/audioinfo.rb', line 103

def bits_per_sample
  @bits_per_sample
end

#bpsObject

Returns the value of attribute bps.



103
104
105
# File 'lib/audioinfo.rb', line 103

def bps
  @bps
end

#channelsObject

Returns the value of attribute channels.



103
104
105
# File 'lib/audioinfo.rb', line 103

def channels
  @channels
end

#sample_rateObject

Returns the value of attribute sample_rate.



103
104
105
# File 'lib/audioinfo.rb', line 103

def sample_rate
  @sample_rate
end

#sFileObject (readonly)

Returns the value of attribute sFile.



104
105
106
# File 'lib/audioinfo.rb', line 104

def sFile
  @sFile
end

#sizeObject (readonly)

Returns the value of attribute size.



104
105
106
# File 'lib/audioinfo.rb', line 104

def size
  @size
end

#timeObject

Returns the value of attribute time.



103
104
105
# File 'lib/audioinfo.rb', line 103

def time
  @time
end

#titleObject

Returns the value of attribute title.



103
104
105
# File 'lib/audioinfo.rb', line 103

def title
  @title
end

#tracknumberObject

Returns the value of attribute tracknumber.



103
104
105
# File 'lib/audioinfo.rb', line 103

def tracknumber
  @tracknumber
end

#yearObject

Returns the value of attribute year.



103
104
105
# File 'lib/audioinfo.rb', line 103

def year
  @year
end

Instance Method Details

#arreglarValor(tag, valor) ⇒ Object

arregla aquellos valores de tag con formatos especiales



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/audioinfo.rb', line 123

def arreglarValor(tag,valor)
valor.gsub!('_',' ')
	case tag
	when 'tracknumber'
		if valor=~/(\d+)\/\d+/
			valor=$1
		elsif valor=~/\[(\d+)\]/
			valor=$1
		elsif valor=~/^(\d+)/
			valor=$1
		end
		valor=nil if valor !~ /\d+/
	when 'year'
		if valor=~/(\d+)[-\/:](\d+)[-\/:](\d+)/
			valor=$3 if $3.length==4
			valor=$1 if $1.length==4
		elsif valor=~/(\d+)\/(\d+)/
			valor=$1
		elsif valor=~/(\d+)/
			valor=$1
		else
			valor=""
		end
	end
	valor.to_utf8 if valor.respond_to?('to_utf8')
end

#arreglarValoresEstandar(aInfo) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/audioinfo.rb', line 149

def arreglarValoresEstandar(aInfo)
	aInfo.each { |tagprop,tagself|
		valor=yield(tagprop)
		valor=arreglarValor(tagself,valor.to_s)
		self.send(tagself+"=",valor) unless (valor.nil? or valor=="")
	}		
end

#incompleto?Boolean

retorna true si falta alguno de los tag basicos, definidos en TAGS

Returns:

  • (Boolean)


158
159
160
# File 'lib/audioinfo.rb', line 158

def incompleto?
	TAGS.detect {|tag| send(tag).nil?}
end

#kbpsObject

entrega los kbps para el archivo



119
120
121
# File 'lib/audioinfo.rb', line 119

def kbps
	@bps/1024.to_f
end

#merge(oInfo) ⇒ Object

recoje los valores de otro AudioInfo::Tipo y los une a los propios



162
163
164
165
166
167
168
169
170
# File 'lib/audioinfo.rb', line 162

def merge(oInfo)
	raise "No es Tipo" if !oInfo.kind_of? AudioInfo::Tipo
	TAGS.each {|tag|
		tag_1=send(tag)
		tag_2=oInfo.send(tag)
		#instance_variable_set(var,tag_2) if tag_1.nil? and !tag_2.nil?
		send(tag+'=',tag_2) if tag_1.nil? and !tag_2.nil?
	}
end