Skip to content

Instantly share code, notes, and snippets.

@advorak advorak/new_code.rb
Created Jan 18, 2016

Embed
What would you like to do?
my_page_data = @pages.collect(&:to_s)
my_signed_on_data = my_page_data.group_by{|t| t.match /((?:[A-Z]|-| )+EXTRA BOARD|BLK|RUN)/;$1.strip unless $1.nil?}.reject{|k,v| k.nil?}
my_signed_on_data.inject({}) do |memo,obj|
obj[1] = obj[1].join "\n"
obj[1] = case obj[0]
when "BLK"
obj[1].scan(/^\s*((?:(?:C|M)_)?\d{4})\s+\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|.*?\$(\d{4}\.\d{2})\s*\$(\d{4}\.\d{2})/).collect{|blks| Hash[[[:block_number, :saturday, :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :cap_id, :name, :bi_weekly_pay_school, :bi_weekly_pay_non_school],blks].transpose]}
when "RUN"
obj[1].scan(/^\s*((?:(?:C|M)_)?\d{3})\s+([SUMTWHF]{2})(.*?)\|(.*)\|(.*?)\$(\d{4}\.\d{2})\s*\$(\d{4}\.\d{2})/).collect{|run| run.collect!(&:strip); Hash[[[:run_number, :days_off, :comments, :cap_id, :name, :bi_weekly_pay_school, :bi_weekly_pay_non_school],run].transpose]}
when /(FULL-TIME|FLOATING EXTRA BOARD)/
obj[1].scan(/^\s*(\d{1,2}\.XL)\s*\|\s+([SUMTWHF]{2})\s+\|(.*?)\|(.*?)\|/).each{|t| t.collect!(&:strip)}.collect{|ebs| Hash[[[:eb_number, :days_off, :cap_id, :name],ebs].transpose]}
end
memo[obj[0]] = obj[1]
memo
end
def signed_on_data
my_page_data = @pages.collect(&:to_s)
my_signed_on_data = my_page_data.group_by{|t| t.match /((?:[A-Z]|-| )+EXTRA BOARD|BLK|RUN)/;$1.strip unless $1.nil?}.reject{|k,v| k.nil?}
my_signed_on_data["RUN"] = my_signed_on_data["RUN"].join("\n").scan(/(\d{3})\s+(\w{2}).*?\|(.*?)\|(.*?)\$(\d{4}\.\d{2}).*?\$(\d{4}\.\d{2})/).collect {|t| t[0],t[2] = t[0].to_i,t[2].to_i; t}.reject{|t| t[2] == 0}
my_signed_on_data["RUN"].each {|t| t[3].strip!}
%w(FULL-TIME FLOATING).each do |eb_type|
current_eb_data = my_signed_on_data["#{eb_type} EXTRA BOARD"].join("\n").scan /(\d+\.XL).*?\|.*?(\w{2}).*?\|.*?(\d{4}).*?\|(.*?)\|/
current_eb_data = current_eb_data.each do |eb_data|
eb_data.collect! {|t| t.to_i.to_s == t.strip.gsub(/^0*/, "") ? t.to_i : t.strip}
end.inject([]) {|memo,obj| x={eb_number: obj[0], days_off: obj[1], name: obj[2]}; memo.push x}
end
my_signed_on_data["FULL-TIME EXTRA BOARD"].join("\n").scan /(\d+\.XL).*?\|.*?(\w{2}).*?\|.*?(\d{4}).*?\|(.*?)\|/
my_signed_on_data["FLOATING EXTRA BOARD"].join("\n").scan /(\d+\.XL).*?\|.*?(\w{2}).*?\|.*?(\d{4}).*?\|(.*?)\|/
my_signed_on_data["BLK"] = my_signed_on_data["BLK"].join("\n").scan(/^\s+(\d{4}).*?\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|.*?\$(\d{4}\.\d{2}).*?\$(\d{4}\.\d{2})/)
my_signed_on_data["BLK"].collect! do |blk|
blk.collect! {|t| t.to_i.to_s == t.strip ? t.to_i : t.strip}
end
@pages.collect(&:to_s).group_by{|t| t.match /((?:[A-Z]|-| )+EXTRA BOARD|BLK|RUN)/;$1.strip unless $1.nil?}.reject{|k,v| k.nil?}["FULL-TIME EXTRA BOARD"][-1]
puts fteb;fteb.scan /(\d+\.XL).*?\|.*?(\w{2}).*?\|.*?(\d{4}).*?\|(.*?)\|/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.