Class: Doattend::Participant

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Participant

Returns a new instance of Participant.



7
8
9
10
11
# File 'lib/doattend/participant.rb', line 7

def initialize(result)
	self.result = result
	#self.info = result['participant_information']
	self.general_info = ['Ticket_Number', 'Email', 'Date', 'Name']
end

Instance Attribute Details

#general_infoObject

Returns the value of attribute general_info.



5
6
7
# File 'lib/doattend/participant.rb', line 5

def general_info
  @general_info
end

#infoObject

Returns the value of attribute info.



5
6
7
# File 'lib/doattend/participant.rb', line 5

def info
  @info
end

#resultObject

Returns the value of attribute result.



5
6
7
# File 'lib/doattend/participant.rb', line 5

def result
  @result
end

Instance Method Details

#ascertain(k, v) ⇒ Object

Count occurences of key/value. Looks like this method is redundant. TODO: Remove this in the next version



30
31
32
33
34
35
36
37
# File 'lib/doattend/participant.rb', line 30

def ascertain(k, v)
	if self.general_info.include? k
		self.result.count{ |p| p[k] == v.downcase }				
	else
		#self.result.map{ |p| p['participant_information'].select{ |i| i['desc'].strip.downcase == k.split('_').join(' ').downcase and i['info'].strip.downcase == v.downcase  } }.flatten.size
		get_participant_info(k, v).size
	end
end

#find(ticket) ⇒ Object

Default Participant Finder. Returns a participant having the specified ticket number.



23
24
25
# File 'lib/doattend/participant.rb', line 23

def find(ticket)
	self.result.select{ |p| p['Ticket_Number'] == ticket }.first
end

#on(date) ⇒ Object



44
45
46
# File 'lib/doattend/participant.rb', line 44

def on(date)
	self.result.select{ |p| Date.iso8601(p['Date']).strftime == date.strftime }
end

#pluck(field) ⇒ Object

Pluck a particular field from participants.



14
15
16
17
18
19
20
# File 'lib/doattend/participant.rb', line 14

def pluck(field)
	if self.general_info.include? field
		self.result.map{ |p| p[field] }
	else
		self.result.map{ |p| p['participant_information'].select{ |a| a['desc'] == field } }.flatten.map{ |x| x['info'] }
	end
end

#registeredObject

Return participants who have registered on a particular date.



40
41
42
# File 'lib/doattend/participant.rb', line 40

def registered
	self
end

#where(k, v) ⇒ Object

Return participant object(s) with a specified key/value.



49
50
51
52
53
54
55
# File 'lib/doattend/participant.rb', line 49

def where(k, v)
	if self.general_info.include? k
		self.result.select{ |p| p[k].downcase == v.downcase }
	else
		get_participant_info(k.downcase, v)
	end
end