paxx 0.1.0 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f651c357e4e05c27513d9748d52424de3be9a25
4
- data.tar.gz: e27012e21a721ac8da851180912368789b72dc4f
3
+ metadata.gz: 8bec9f544f4ff2bac2668a330b44b83b5cf12562
4
+ data.tar.gz: d3697992c83956be40c98c241388f887e705a40b
5
5
  SHA512:
6
- metadata.gz: a91be8ec432e9cb4fdec4639adfcd6d8ef414fce2d30ea69a061b403de66b38f2db26562032d0728aa3d4c69828ddabdf9ef6bd59e013a5436ad23901a9f435f
7
- data.tar.gz: a3f6f625c37addebc978b1fcfdd3a54c103ce22878929a9595fe418b4a037945a31ea62a85afe39788c0de66c7348ac7160e57d3693eb79c7faa167b84126485
6
+ metadata.gz: 091afc2da2d389fc695029e5904ead019dd11b1bee771d0bc6eb6dd8f59593c58285d71e93dddb06856fdad434732857a3d80a29b3fd7edc8bfa04d6a59c750a
7
+ data.tar.gz: ea7dd4126728336a7b746284217e3c926468d1889b8a39a155f9a8a45cf913c610b3ab776fe4137f5f854687de1391b02d5006781f607049c4bb3635990bf054
data/lib/paxx.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "paxx/date/date_parser"
2
+ require "paxx/names/name_normalizer"
2
3
  require "paxx/version"
3
4
 
4
5
  module Paxx
@@ -39,5 +39,14 @@ module Paxx
39
39
  Time.local(year, month, day)
40
40
  end
41
41
 
42
+ def calc_age(dob)
43
+ return nil unless dob
44
+ now = Time.now.utc.to_date
45
+ now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
46
+ end
47
+
42
48
  end
49
+
50
+
51
+
43
52
  end
@@ -0,0 +1,86 @@
1
+ module Paxx
2
+
3
+ class NameNormalizer
4
+ attr_reader :name, :first_name, :last_name, :full_name
5
+
6
+ def initialize src_name
7
+ @name = src_name
8
+ @first_name, @last_name = splitt
9
+ end
10
+
11
+ def valid
12
+ !(name.to_s.strip.length == 0)
13
+ end
14
+
15
+ def normalize(txt=name)
16
+ txt.to_s.gsub("\n", ' ').squeeze(' ').strip
17
+ end
18
+
19
+
20
+ def subst_norwegian_chars(txt)
21
+ [["æ", "ae"], ["ø", "oe"], ["å", "aa"]].each do |int|
22
+ txt = txt.gsub(int[0], int[1])
23
+ end
24
+ [["Æ", "AE"], ["Ø", "OE"], ["Å", "AA"]].each do |int|
25
+ txt = txt.gsub(int[0], int[1])
26
+ end
27
+ txt
28
+ end
29
+
30
+ def camelize(txt=name)
31
+ txt.split(/[^a-zøæåØÆÅ0-9]/i).map { |w| w.capitalize }.join if txt
32
+ end
33
+
34
+ def splitt
35
+ words = name.to_s.split()
36
+ if words.count > 1
37
+ last_name = words.last
38
+ words.pop
39
+ first_name = words.join(" ")
40
+ else
41
+ first_name = name
42
+ last_name=""
43
+ end
44
+ [camelize(first_name), camelize(last_name)]
45
+ end
46
+
47
+ def as_id(txt=name)
48
+ subst_norwegian_chars(txt.delete(" ").delete("-")).downcase if txt
49
+ end
50
+
51
+ def compose_short_ref first,last
52
+ "#{first}#{last}"
53
+ end
54
+
55
+ def last_part name,counter
56
+ if name && counter < name.length
57
+ name[0..counter]
58
+ else
59
+ "#{name}#{counter-name.length+1}"
60
+ end
61
+ end
62
+
63
+ def as_short_ref
64
+ counter = 0
65
+ unique = !block_given?
66
+ xref = ""
67
+ start = camelize(as_id(first_name))
68
+
69
+ begin
70
+ shortref = compose_short_ref start,xref
71
+
72
+ if !unique
73
+ unique = yield shortref
74
+ if !unique
75
+ counter += 1
76
+ xref = last_part(camelize(as_id(last_name)),counter)
77
+ end
78
+ end
79
+ end while !unique && counter < 100
80
+ shortref
81
+ end
82
+
83
+
84
+ end
85
+
86
+ end
data/lib/paxx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Paxx
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paxx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - leffen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-05 00:00:00.000000000 Z
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - bin/setup
72
72
  - lib/paxx.rb
73
73
  - lib/paxx/date/date_parser.rb
74
+ - lib/paxx/names/name_normalizer.rb
74
75
  - lib/paxx/version.rb
75
76
  - paxx.gemspec
76
77
  homepage: http://github.com/leffen/paxx