c12-commons 0.0.1.beta1 → 0.0.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,4 +20,6 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency 'rspec', '~> 2'
22
22
  s.add_development_dependency 'simplecov'
23
+
24
+ s.add_runtime_dependency 'actionpack', '~> 3'
23
25
  end
@@ -1,4 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
+ require 'action_controller'
4
+
5
+ include ActionView::Helpers::NumberHelper
6
+
3
7
  require 'c12-commons/version'
4
- require 'c12-commons/ruby'
8
+ require 'c12-commons/ruby'
9
+ require 'c12-commons/ka'
@@ -0,0 +1,43 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module C12
4
+
5
+ # This module is used for managing Georgian locale data.
6
+ module KA
7
+ private
8
+
9
+ MONTHS_EN_SHORT = {'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12}
10
+ MONTHS_EN = {'january' => 1, 'february' => 2, 'march' => 3, 'april' => 4, 'may' => 5, 'june' => 6, 'july' => 7, 'august' => 8, 'september' => 9, 'october' => 10, 'november' => 11, 'december' => 12}
11
+ MONTHS = ['იანვარი', 'თებერვალი', 'მარტი', 'აპრილი', 'მაისი', 'ივნისი', 'ივლისი', 'აგვისტო', 'სექტემბერი', 'ოქტომბერი', 'ნოემბერი', 'დეკემბერი']
12
+ MONTHS_SHORT = ['იან', 'თებ', 'მარ', 'აპრ', 'მაი', 'ივნ', 'ივლ', 'აგვ', 'სექ', 'ოქტ', 'ნოე', 'დეკ']
13
+
14
+ public
15
+
16
+ # Returns the name of the month in georgian.
17
+ #
18
+ # Month can be given as a number (January is <code>1</code>)
19
+ # or as an instance of <code>Time</code>. Alternatively you
20
+ # can use month name in English (either short or long names).
21
+ # <code>nil</code> value for the argument returns <code>nil</code>
22
+ # as a month name.
23
+ #
24
+ # If you need a short version of the month's name, then use
25
+ # <code>:format => :short</code> in options.
26
+ def self.month(month, opts = {})
27
+ if month.instance_of? Time
28
+ index = month.month
29
+ elsif month.instance_of? Fixnum
30
+ index = month % 12
31
+ elsif month.instance_of? String
32
+ index = MONTHS_EN[month.downcase] || MONTHS_EN_SHORT[month.downcase]
33
+ end
34
+ (opts[:format] == :short ? MONTHS_SHORT : MONTHS)[index - 1] if index
35
+ end
36
+
37
+ #
38
+ def self.number(number, opts = {})
39
+ number_with_precision(number, :precision => opts[:precision] || 2, :delimiter => ' ', :separator => ',')
40
+ end
41
+
42
+ end
43
+ end
@@ -1,14 +1,17 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  # Returns the first argument unless it's <code>nil</code>,
4
- # then the second argument is returned.
4
+ # in which casr the second argument is returned.
5
5
  def nvl(value, value_if_nil = 0)
6
6
  value.nil? ? value_if_nil : value
7
7
  end
8
8
 
9
+ # Determines emptiness of the argument.
10
+ #
9
11
  # <code>nil</code> is empty, <code>''</code> is empty,
10
12
  # empty <code>Array</code> or <code>Array</code> of <code>nil</code>s is empty.
11
- # Other classes are teseted on response to <code>:empty?</code>.
13
+ # Other objects are empty if they respond to <code>empty?</code> command and it returns <code>true</code>.
14
+ # In other cases the object is not empty.
12
15
  def empty?(value)
13
16
  return true if value.nil?
14
17
  return value.strip.empty? if value.instance_of? String
@@ -16,3 +19,11 @@ def empty?(value)
16
19
  return value.empty? if value.respond_to? :empty?
17
20
  false
18
21
  end
22
+
23
+ include ActionView::Helpers::NumberHelper
24
+
25
+ # Format number using given precission. Number is formatted
26
+ # using Georgian conventions for decimal and thousands separators.
27
+ def number_format(number, precision = 2)
28
+ C12::KA.number(number, :precision => precision)
29
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module C12
3
3
  module Commons
4
- VERSION = "0.0.1.beta1"
4
+ VERSION = "0.0.1.beta2"
5
5
  end
6
6
  end
@@ -0,0 +1,86 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'c12-commons'
4
+
5
+ def test_full_month_name(month, name)
6
+ describe "name for month #{month}" do
7
+ subject { C12::KA.month(month) }
8
+ it("is #{name}") { should == name }
9
+ end
10
+ end
11
+
12
+ test_full_month_name(1, 'იანვარი')
13
+ test_full_month_name(2, 'თებერვალი')
14
+ test_full_month_name(3, 'მარტი')
15
+ test_full_month_name(4, 'აპრილი')
16
+ test_full_month_name(5, 'მაისი')
17
+ test_full_month_name(6, 'ივნისი')
18
+ test_full_month_name(7, 'ივლისი')
19
+ test_full_month_name(8, 'აგვისტო')
20
+ test_full_month_name(9, 'სექტემბერი')
21
+ test_full_month_name(10, 'ოქტომბერი')
22
+ test_full_month_name(11, 'ნოემბერი')
23
+ test_full_month_name(12, 'დეკემბერი')
24
+
25
+ test_full_month_name(Time.local(2012, 1, 1), 'იანვარი')
26
+ test_full_month_name(Time.local(2012, 2, 1), 'თებერვალი')
27
+ test_full_month_name(Time.local(2012, 3, 1), 'მარტი')
28
+ test_full_month_name(Time.local(2012, 4, 1), 'აპრილი')
29
+ test_full_month_name(Time.local(2012, 5, 1), 'მაისი')
30
+ test_full_month_name(Time.local(2012, 6, 1), 'ივნისი')
31
+ test_full_month_name(Time.local(2012, 7, 1), 'ივლისი')
32
+ test_full_month_name(Time.local(2012, 8, 1), 'აგვისტო')
33
+ test_full_month_name(Time.local(2012, 9, 1), 'სექტემბერი')
34
+ test_full_month_name(Time.local(2012, 10, 1), 'ოქტომბერი')
35
+ test_full_month_name(Time.local(2012, 11, 1), 'ნოემბერი')
36
+ test_full_month_name(Time.local(2012, 12, 1), 'დეკემბერი')
37
+
38
+ test_full_month_name('Jan', 'იანვარი')
39
+ test_full_month_name('Feb', 'თებერვალი')
40
+ test_full_month_name('Mar', 'მარტი')
41
+ test_full_month_name('Apr', 'აპრილი')
42
+ test_full_month_name('May', 'მაისი')
43
+ test_full_month_name('Jun', 'ივნისი')
44
+ test_full_month_name('Jul', 'ივლისი')
45
+ test_full_month_name('Aug', 'აგვისტო')
46
+ test_full_month_name('Sep', 'სექტემბერი')
47
+ test_full_month_name('Oct', 'ოქტომბერი')
48
+ test_full_month_name('Nov', 'ნოემბერი')
49
+ test_full_month_name('Dec', 'დეკემბერი')
50
+
51
+ test_full_month_name('january', 'იანვარი')
52
+ test_full_month_name('february', 'თებერვალი')
53
+ test_full_month_name('march', 'მარტი')
54
+ test_full_month_name('april', 'აპრილი')
55
+ test_full_month_name('may', 'მაისი')
56
+ test_full_month_name('june', 'ივნისი')
57
+ test_full_month_name('july', 'ივლისი')
58
+ test_full_month_name('august', 'აგვისტო')
59
+ test_full_month_name('september', 'სექტემბერი')
60
+ test_full_month_name('october', 'ოქტომბერი')
61
+ test_full_month_name('november', 'ნოემბერი')
62
+ test_full_month_name('december', 'დეკემბერი')
63
+
64
+ test_full_month_name(nil, nil)
65
+
66
+ def test_short_month_name(month, name)
67
+ describe "short name for month #{month}" do
68
+ subject { C12::KA.month(month, :format => :short) }
69
+ it("is #{name}") { should == name }
70
+ end
71
+ end
72
+
73
+ test_short_month_name(1, 'იან')
74
+ test_short_month_name(2, 'თებ')
75
+ test_short_month_name(3, 'მარ')
76
+ test_short_month_name(4, 'აპრ')
77
+ test_short_month_name(5, 'მაი')
78
+ test_short_month_name(6, 'ივნ')
79
+ test_short_month_name(7, 'ივლ')
80
+ test_short_month_name(8, 'აგვ')
81
+ test_short_month_name(9, 'სექ')
82
+ test_short_month_name(10, 'ოქტ')
83
+ test_short_month_name(11, 'ნოე')
84
+ test_short_month_name(12, 'დეკ')
85
+
86
+ test_full_month_name(nil, nil)
@@ -30,3 +30,15 @@ test_emptiness(1, false)
30
30
  test_emptiness('texts', false)
31
31
  test_emptiness([1, 2, 3], false)
32
32
  test_emptiness({:a => 1, :b=>2}, false)
33
+
34
+ def test_number_formatting(number, precision, format)
35
+ describe "#{number} should be formated" do
36
+ subject{ number_format(number, precision) }
37
+ it("as #{format}") { should == format }
38
+ end
39
+ end
40
+
41
+ test_number_formatting(1, 0, '1')
42
+ test_number_formatting(1000, 0, '1 000')
43
+ test_number_formatting(1000, 3, '1 000,000')
44
+ test_number_formatting(123456.789, 2, '123 456,79')
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.1.beta1
4
+ version: 0.0.1.beta2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &80797510 !ruby/object:Gem::Requirement
16
+ requirement: &70293265727240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *80797510
24
+ version_requirements: *70293265727240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simplecov
27
- requirement: &80796540 !ruby/object:Gem::Requirement
27
+ requirement: &70293265726820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *80796540
35
+ version_requirements: *70293265726820
36
+ - !ruby/object:Gem::Dependency
37
+ name: actionpack
38
+ requirement: &70293265726200 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70293265726200
36
47
  description: Common functionality for Ruby code
37
48
  email:
38
49
  - dimitri@c12.ge
@@ -47,8 +58,10 @@ files:
47
58
  - Rakefile
48
59
  - c12-commons.gemspec
49
60
  - lib/c12-commons.rb
61
+ - lib/c12-commons/ka.rb
50
62
  - lib/c12-commons/ruby.rb
51
63
  - lib/c12-commons/version.rb
64
+ - spec/c12-commons/month_spec.rb
52
65
  - spec/c12-commons/ruby_spec.rb
53
66
  - spec/spec_helper.rb
54
67
  homepage: ''
@@ -71,9 +84,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
84
  version: 1.3.1
72
85
  requirements: []
73
86
  rubyforge_project: c12-commons
74
- rubygems_version: 1.8.13
87
+ rubygems_version: 1.8.15
75
88
  signing_key:
76
89
  specification_version: 3
77
90
  summary: Common functions
78
- test_files: []
91
+ test_files:
92
+ - spec/c12-commons/month_spec.rb
93
+ - spec/c12-commons/ruby_spec.rb
94
+ - spec/spec_helper.rb
79
95
  has_rdoc: