Class: Doattend::Participant
- Inherits:
-
Object
- Object
- Doattend::Participant
- Defined in:
- lib/doattend/participant.rb
Instance Attribute Summary collapse
-
#general_info ⇒ Object
Returns the value of attribute general_info.
-
#info ⇒ Object
Returns the value of attribute info.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#ascertain(k, v) ⇒ Object
Count occurences of key/value.
-
#find(ticket) ⇒ Object
Default Participant Finder.
-
#initialize(result) ⇒ Participant
constructor
A new instance of Participant.
- #on(date) ⇒ Object
-
#pluck(field) ⇒ Object
Pluck a particular field from participants.
-
#registered ⇒ Object
Return participants who have registered on a particular date.
-
#where(k, v) ⇒ Object
Return participant object(s) with a specified key/value.
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_info ⇒ Object
Returns the value of attribute general_info.
5 6 7 |
# File 'lib/doattend/participant.rb', line 5 def general_info @general_info end |
#info ⇒ Object
Returns the value of attribute info.
5 6 7 |
# File 'lib/doattend/participant.rb', line 5 def info @info end |
#result ⇒ Object
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 |
#registered ⇒ Object
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 |