class Doattend::Participant

Attributes

general_info[RW]
info[RW]
result[RW]

Public Class Methods

new(result) click to toggle source
# 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

Public Instance Methods

ascertain(k, v) click to toggle source

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

# 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) click to toggle source

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

# File lib/doattend/participant.rb, line 23
def find(ticket)
        self.result.select{ |p| p['Ticket_Number'] == ticket }.first
end
on(date) click to toggle source
# File lib/doattend/participant.rb, line 44
def on(date)
        self.result.select{ |p| Date.iso8601(p['Date']).strftime == date.strftime }
end
pluck(field) click to toggle source

Pluck a particular field from participants.

# 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() click to toggle source

Return participants who have registered on a particular date.

# File lib/doattend/participant.rb, line 40
def registered
        self
end
where(k, v) click to toggle source

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

# 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

Private Instance Methods

get_participant_info(k, v) click to toggle source
# File lib/doattend/participant.rb, line 58
def get_participant_info(k, v)
        participants = []
        self.result.each do |p|
                p['participant_information'].each do |pz|
                        participants << p if pz['desc'] == k and pz['info'].downcase == v.downcase
                end
        end
        participants
end