c12-commons 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/c12-commons.rb CHANGED
@@ -7,3 +7,5 @@ require 'c12-commons/version'
7
7
  require 'c12-commons/core'
8
8
  require 'c12-commons/ka'
9
9
  require 'c12-commons/pdf'
10
+ require 'c12-commons/email'
11
+ require 'c12-commons/mobile'
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module C12
3
+ def self.correct_email?(email)
4
+ not not (email =~ /^\S+@\S+$/)
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module C12
3
+ # მობილურის "კომპაქტიზაცია": ტოვებს მხოლოდ ციფრებს.
4
+ def self.compact_mobile(mob)
5
+ mob.scan(/[0-9]/).join('') if mob
6
+ end
7
+
8
+ # ამოწმებს მობილურის ნომრის კორექტულობას.
9
+ # კორექტული მობილურის ნომერი უნდა შეიცავდეს 9 ციფრს.
10
+ def self.correct_mobile?(mob)
11
+ not not (compact_mobile(mob) =~ /^[0-9]{9}$/)
12
+ end
13
+
14
+ # აფორმატებს მობილურს (XXX)XXX-XXX სახით.
15
+ def self.format_mobile(mob)
16
+ mob = C12.compact_mobile(mob)
17
+ "(#{mob[0..2]})#{mob[3..5]}-#{mob[6..8]}"
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module C12
3
3
  module Commons
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
6
- end
6
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ def correct_email(email)
5
+ context email do
6
+ subject { C12.correct_email? email }
7
+ it('სწორია') { should == true }
8
+ end
9
+ end
10
+
11
+ def incorrect_email(email)
12
+ context email do
13
+ subject { C12.correct_email? email }
14
+ it('არასწორია') { should == false }
15
+ end
16
+ end
17
+
18
+ describe 'ელექტრონული ფოსტის ფორმატი' do
19
+ correct_email 'dimitri@c12.ge'
20
+ correct_email 'dimakura@gmail.com'
21
+ correct_email 'dimitri.kurashvili@telasi.ge'
22
+ incorrect_email 'dimitri@'
23
+ incorrect_email 'dimitri'
24
+ incorrect_email '@c12.ge'
25
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ def correct_mobile(mob)
5
+ context mob do
6
+ subject { C12.correct_mobile? mob }
7
+ it('უნდა იყოს სწორი') { should == true }
8
+ end
9
+ end
10
+
11
+ def incorrect_mobile(mob)
12
+ context mob do
13
+ subject { C12.correct_mobile? mob }
14
+ it('არაა სწორი') { should == false }
15
+ end
16
+ end
17
+
18
+ def check_mobile_format(mob, formatted)
19
+ context "#{mob} as #{formatted}" do
20
+ subject { formatted }
21
+ it { should == C12.format_mobile(mob) }
22
+ end
23
+ end
24
+
25
+ describe 'მობილურის სისწორის შემოწმება' do
26
+ correct_mobile '595335514'
27
+ correct_mobile '599422451'
28
+ correct_mobile '(595)335-514'
29
+ correct_mobile '(595)33-55-14'
30
+ correct_mobile '+(595)33-55-14'
31
+
32
+ incorrect_mobile '59533551'
33
+ incorrect_mobile '123'
34
+ incorrect_mobile '5953355145'
35
+ incorrect_mobile nil
36
+ end
37
+
38
+ describe 'მობილურის ფორმატის შემოწმება' do
39
+ check_mobile_format '595335514', '(595)335-514'
40
+ check_mobile_format '(595)33-55-14', '(595)335-514'
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c12-commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-12 00:00:00.000000000 Z
12
+ date: 2012-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &85334950 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '2'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *85334950
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: simplecov
27
- requirement: &85334750 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *85334750
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: actionpack
38
- requirement: &85334480 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '3'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *85334480
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: prawn
49
- requirement: &85334230 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0.12'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *85334230
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.12'
58
78
  description: Simple functionality used in my projects
59
79
  email:
60
80
  - dimitri@c12.ge
@@ -70,7 +90,9 @@ files:
70
90
  - c12-commons.gemspec
71
91
  - lib/c12-commons.rb
72
92
  - lib/c12-commons/core.rb
93
+ - lib/c12-commons/email.rb
73
94
  - lib/c12-commons/ka.rb
95
+ - lib/c12-commons/mobile.rb
74
96
  - lib/c12-commons/pdf-assets/DejaVuSans-Bold.ttf
75
97
  - lib/c12-commons/pdf-assets/DejaVuSans-BoldOblique.ttf
76
98
  - lib/c12-commons/pdf-assets/DejaVuSans-Oblique.ttf
@@ -83,6 +105,8 @@ files:
83
105
  - lib/c12-commons/version.rb
84
106
  - spec/c12-commons/core_spec.rb
85
107
  - spec/c12-commons/date_spec.rb
108
+ - spec/c12-commons/email_spec.rb
109
+ - spec/c12-commons/mobile_spec.rb
86
110
  - spec/c12-commons/number_spec.rb
87
111
  - spec/c12-commons/pdf_spec.rb
88
112
  - spec/spec_helper.rb
@@ -106,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
130
  version: '0'
107
131
  requirements: []
108
132
  rubyforge_project: c12-commons
109
- rubygems_version: 1.8.13
133
+ rubygems_version: 1.8.19
110
134
  signing_key:
111
135
  specification_version: 3
112
136
  summary: Simple functions