class Podpisy::Signatures
Public Class Methods
new(fn, **opts)
click to toggle source
# File lib/podpisy/signatures.rb, line 5 def initialize(fn, **opts) @fn = fn @resolve_areas = opts[:areas] or false if @resolve_areas @kody = Postcodes.new else @kody = nil end @area_types = [:m, :p, :w] end
Public Instance Methods
first_last_name(row)
click to toggle source
# File lib/podpisy/signatures.rb, line 49 def first_last_name(row) fn = row['first_name'] || row['name'].split(' ')[0...-1].join(' ') ln = row['last_name'] || row['name'].split(' ')[-1] [fn, ln] end
process_row(row)
click to toggle source
# File lib/podpisy/signatures.rb, line 23 def process_row(row) row.headers.inject({}) do |m, h| if @resolve_areas && h == 'postcode' m['postcode'] = @kody.unambiguous(row[h], *@area_types) else m[h] = row[h] end m end end
remove_special_chars(s)
click to toggle source
# File lib/podpisy/signatures.rb, line 16 def remove_special_chars(s) s = s.gsub(/[~_]/, '-') s = s.gsub(/&/, ' i ') s = s.gsub(/[%${}^\\#]/, '') s end
to_csv(o = STDOUT)
click to toggle source
# File lib/podpisy/signatures.rb, line 34 def to_csv(o = STDOUT) headers = nil CSV(o) do |out| CSV.foreach(@fn, headers: true, col_sep: ',') do |row| if headers.nil? headers = row.headers if headers.nil? out << headers end colvals = process_row(row) out << headers.map { |h| colvals[h] } end end end
to_tex(o = STDOUT)
click to toggle source
# File lib/podpisy/signatures.rb, line 55 def to_tex(o = STDOUT) i = 1 CSV.foreach(@fn, headers: true, col_sep: ',') do |row| if @resolve_areas city = @kody.unambiguous(row['postcode'], :m, :p, :w) else city = row['postcode'] end fn, ln = first_last_name(row) f = remove_special_chars(fn || '').capitalize l = remove_special_chars(fn || '').capitalize o.puts "#{i}. & \\first{#{f}} \\last{#{l}} & \\city{#{city}} \\\\" i+=1 end end