podpisy 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ require 'set'
3
+
4
+ module Podpisy
5
+ class Postcodes
6
+ @@format = {m:"%s", p: "Powiat %s", w: "Województwo %s"}
7
+
8
+ def initialize
9
+ fn = File.expand_path('kody.csv', File.dirname(__FILE__))
10
+ @kody = {}
11
+
12
+ CSV.foreach(fn, headers: true, col_sep: ',') do |row|
13
+ x = @kody[row['kod']]
14
+ x = {m:Set.new, p:Set.new, w:Set.new} unless x
15
+ x[:m] << row['miejscowosc']
16
+ x[:p] << row['powiat']
17
+ x[:w] << row['wojewodztwo']
18
+ @kody[row['kod']] = x
19
+ end
20
+ end
21
+
22
+ def unambiguous(kod, *order)
23
+ x = @kody[kod]
24
+ return '' unless x
25
+ order.each do |at|
26
+ next if x[at].length > 1
27
+ return @@format[at] % x[at].first
28
+ end
29
+ ''
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,57 @@
1
+ require 'csv'
2
+
3
+ module Podpisy
4
+ class Signatures
5
+ def initialize(fn, **opts)
6
+ @fn = fn
7
+ @kody = Postcodes.new
8
+ @resolve_areas = opts[:areas] or false
9
+ @area_types = [:m, :p, :w]
10
+ end
11
+
12
+ def remove_special_chars(s)
13
+ s = s.gsub(/[~_]/, '-')
14
+ s = s.gsub(/&/, ' i ')
15
+ s = s.gsub(/[%${}^\\#]/, '')
16
+ s
17
+ end
18
+
19
+ def process_row(row)
20
+ row.headers.inject({}) do |m, h|
21
+ if @resolve_areas && h == 'postcode'
22
+ m['postcode'] = @kody.unambiguous(row[h], *@area_types)
23
+ else
24
+ m[h] = row[h]
25
+ end
26
+ m
27
+ end
28
+ end
29
+
30
+ def to_csv(o = STDOUT)
31
+ headers = nil
32
+ CSV(o) do |out|
33
+ CSV.foreach(@fn, headers: true, col_sep: ',') do |row|
34
+ if headers.nil?
35
+ headers = row.headers if headers.nil?
36
+ out << headers
37
+ end
38
+
39
+ colvals = process_row(row)
40
+ out << headers.map { |h| colvals[h] }
41
+ end
42
+ end
43
+ end
44
+
45
+ def to_tex(o = STDOUT)
46
+ i = 1
47
+ CSV.foreach(@fn, headers: true, col_sep: ',') do |row|
48
+ city= @kody.unambiguous(row['postcode'], :m, :p, :w)
49
+ f = remove_special_chars(row['first_name'] || '').capitalize
50
+ l = remove_special_chars(row['last_name'] || '').capitalize
51
+ o.puts "#{i}. & \\first{#{f}} \\last{#{l}} & \\city{#{city}} \\\\"
52
+ i+=1
53
+ end
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,3 @@
1
+ module Podpisy
2
+ VERSION = "0.1.0"
3
+ end
data/lib/podpisy.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "podpisy/version"
2
+ require 'podpisy/signatures'
3
+ require 'podpisy/postcodes'
4
+ require 'podpisy/cli'
5
+
6
+ module Podpisy
7
+ end
data/podpisy.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "podpisy/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "podpisy"
9
+ spec.version = Podpisy::VERSION
10
+ spec.authors = ["Marcin Koziej"]
11
+ spec.email = ["marcin@akcjademokracja.pl"]
12
+
13
+ spec.summary = %q{Command for generating and manipulating signatures}
14
+ spec.description = %q{This command is a usefull tool for manipulating CSV files with signatures and generating petition deliveries in PDF}
15
+ spec.homepage = "https://gitlab.com/akcjademokracja/podpisy"
16
+ spec.license = "MIT"
17
+
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "bin"
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_runtime_dependency 'clamp', '~> 1.3', '>= 1.3.0'
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: podpisy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Koziej
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.16'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description: This command is a usefull tool for manipulating CSV files with signatures
76
+ and generating petition deliveries in PDF
77
+ email:
78
+ - marcin@akcjademokracja.pl
79
+ executables:
80
+ - console
81
+ - podpisy
82
+ - setup
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - ".gitignore"
87
+ - ".rspec"
88
+ - ".travis.yml"
89
+ - CODE_OF_CONDUCT.md
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/podpisy
97
+ - bin/setup
98
+ - lib/podpisy.rb
99
+ - lib/podpisy/cli.rb
100
+ - lib/podpisy/kody.csv
101
+ - lib/podpisy/postcodes.rb
102
+ - lib/podpisy/signatures.rb
103
+ - lib/podpisy/version.rb
104
+ - podpisy.gemspec
105
+ homepage: https://gitlab.com/akcjademokracja/podpisy
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.14.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Command for generating and manipulating signatures
129
+ test_files: []