Class: Catori::Query

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

Instance Method Summary collapse

Constructor Details

#initialize(hQuery) ⇒ Query

Returns a new instance of Query.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/catori/Query.rb', line 4

def initialize(hQuery)
	@hQuery=hQuery
	@db = Catori::Db.conectar
	
	aCond=Array.new
	aCond.push("(artist_name like '%"+@hQuery['artist'].to_s+"%')") if !@hQuery['artist'].nil?
	aCond.push("(album_name like '%"+@hQuery['album'].to_s+"%')") if !@hQuery['album'].nil?
	aCond.push("(song_name like '%"+@hQuery['title'].to_s+"%')") if !@hQuery['title'].nil?
	aCond.push("(cd_id ='"+@hQuery['cd'].to_s+"')") if !@hQuery['cd'].nil?
	aCond.push("(file_name like '%"+@hQuery['file'].to_s+"%')") if !@hQuery['file'].nil?
	sCond=aCond.join(" AND ")
	@sQuery="SELECT * from edicion WHERE "+sCond+" ORDER by cd_id, artist_name, album_name, as_track,song_name,file_name"
end

Instance Method Details

#gtk(widget, pix) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/catori/Query.rb', line 44

def gtk(widget,pix)
	ts=Gtk::TreeStore.new(String,String,String,String,Gdk::Pixbuf)
	widget.model=ts
	widget.headers_visible=true
	cd=nil
	artist=nil
	album=nil
	cdi=nil
	artisti=nil
	albumi=nil
	@db.select_all(@sQuery) {|row|
		if row['cd_id']!=cd
			cdi=ts.append(nil) 
			artisti=nil
			albumi=nil
			artist=nil
			album=nil
		end
		cd=row['cd_id']
		cdi[0]=cd
		cdi[4]=pix['cd']
		artisti=ts.append(cdi) if row['artist_name']!=artist
		artist=row['artist_name']
		artisti[0]=artist
		artisti[4]=pix['artist']
		albumi=ts.append(artisti) if row['album_name']!=album
		album=row['album_name']
		albumi[0]=album+"("+row['album_year'].to_s+")"
		albumi[4]=pix['album']
		titlei=ts.append(albumi)
		titlei[1]=row['as_track'].to_s
		titlei[2]=row['song_name']
		titlei[3]=row['file_name']
		titlei[4]=pix['song']
		# p row
	}
end

#plainObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/catori/Query.rb', line 17

def plain
	sSupport= AudioInfo::SUPPORT.join('|')
	out=[]
	@db.select_all(@sQuery) {|row|
		row['file_name']=~/\.(#{sSupport})$/i
		sType=$1
		out << sprintf("CD:%s , Artist: %s,Album: %s, Song:[%02d] %s, Type: %s",row['cd_id'],row['artist_name'], row['album_name'],row['as_track'],row['song_name'],sType)
	}
	out.join("\n")

end

#xmlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/catori/Query.rb', line 28

def xml
	require "rexml/document"
	doc=REXML::Document.new
	root=doc.add_element('catori')
	@db.select_all(@sQuery) {|row|
		file=root.add_element('file', {'cd'=>row['cd_id'], 'path'=>row['file_name'],'id'=>row['file_id']})
		file.add_element('artist').text=row['artist_name']
		file.add_element('album').text=row['album_name']
		file.add_element('tracknumber').text=row['as_track'].to_s
		file.add_element('title').text=row['song_name']
		file.add_element('year').text=row['album_year'].to_s
	}
	s=""
	doc.write(s,1,0)
	s
end