c12-commons 0.0.1.beta2 → 0.0.1.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ coverage/*
6
+ tmp/*
data/c12-commons.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "c12-commons/version"
3
+ require "c12/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "c12-commons"
7
7
  s.version = C12::Commons::VERSION
8
8
  s.authors = ["Dimitri Kurashvili"]
9
9
  s.email = ["dimitri@c12.ge"]
10
- s.homepage = ""
11
- s.summary = %q{Common functions}
12
- s.description = %q{Common functionality for Ruby code}
10
+ s.homepage = "http://c12.ge"
11
+ s.summary = %q{Simple functions}
12
+ s.description = %q{Simple functionality used in my projects}
13
13
 
14
14
  s.rubyforge_project = "c12-commons"
15
15
 
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'simplecov'
23
23
 
24
24
  s.add_runtime_dependency 'actionpack', '~> 3'
25
+ s.add_runtime_dependency 'prawn', '~> 0.12'
25
26
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  # Returns the first argument unless it's <code>nil</code>,
4
- # in which casr the second argument is returned.
4
+ # in which case 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
data/lib/c12/ka.rb ADDED
@@ -0,0 +1,138 @@
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
+ # Georgian number formatter.
38
+ def self.number(number, opts = {})
39
+ number_with_precision(number, :precision => opts[:precision] || 2, :delimiter => ' ', :separator => ',')
40
+ end
41
+
42
+ # Tokenize integer argument to georgian language.
43
+ #
44
+ # Example usage:
45
+ #
46
+ # C12::KA::tokenize(1) => 'ერთი'
47
+ # C12::KA::tokenize(2) => 'ორი'
48
+ #
49
+ # The maximum value for the argument is the value <code>999,999,999,999</code>.
50
+ def self.tokenize(num)
51
+ num_ge_0 = nvl(num, 0).abs
52
+ if num < 0
53
+ "მინუს #{tokenize_int_ge_0(num_ge_0)}"
54
+ else
55
+ tokenize_int_ge_0(num_ge_0)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def self.tokenize_int_ge_0(num)
62
+ case num
63
+ when 0 then return 'ნული'
64
+ when 1 then return 'ერთი'
65
+ when 2 then return 'ორი'
66
+ when 3 then return 'სამი'
67
+ when 4 then return 'ოთხი'
68
+ when 5 then return 'ხუთი'
69
+ when 6 then return 'ექვსი'
70
+ when 7 then return 'შვიდი'
71
+ when 8 then return 'რვა'
72
+ when 9 then return 'ცხრა'
73
+ when 10 then return 'ათი'
74
+ when 11 then return 'თერთმეტი'
75
+ when 12 then return 'თორმეტი'
76
+ when 13 then return 'ცამეტი'
77
+ when 14 then return 'თოთხმეტი'
78
+ when 15 then return 'თხუთმეტი'
79
+ when 16 then return 'თექვსმეტი'
80
+ when 17 then return 'ჩვიდმეტი'
81
+ when 18 then return 'თვრამეტი'
82
+ when 19 then return 'ცხრამეტი'
83
+ when 20 then return 'ოცი'
84
+ when 40 then return 'ორმოცი'
85
+ when 60 then return 'სამოცი'
86
+ when 80 then return 'ოთხმოცი'
87
+ when 100 then return 'ასი'
88
+ when 200 then return 'ორასი'
89
+ when 300 then return 'სამასი'
90
+ when 400 then return 'ოთხასი'
91
+ when 500 then return 'ხუთასი'
92
+ when 600 then return 'ექვსასი'
93
+ when 700 then return 'შვიდასი'
94
+ when 800 then return 'რვაასი'
95
+ when 900 then return 'ცხრაასი'
96
+ when 1000 then return 'ათასი'
97
+ when 1000000 then return 'მილიონი'
98
+ when 1000000000 then return 'მილიარდი'
99
+ end
100
+ return "ოცდა #{tokenize_int_ge_0(num-20)}" if num > 20 and num < 40
101
+ return "ორმოცდა #{tokenize_int_ge_0(num-40)}" if num > 40 and num < 60
102
+ return "სამოცდა #{tokenize_int_ge_0(num-60)}" if num > 60 and num < 80
103
+ return "ოთხმოცდა #{tokenize_int_ge_0(num-80)}" if num > 80 and num < 100
104
+ return "ას #{tokenize_int_ge_0(num-100)}" if num > 100 and num < 200
105
+ return "ორას #{tokenize_int_ge_0(num-200)}" if num > 200 and num < 300
106
+ return "სამას #{tokenize_int_ge_0(num-300)}" if num > 300 and num < 400
107
+ return "ოთხას #{tokenize_int_ge_0(num-400)}" if num > 400 and num < 500
108
+ return "ხუთას #{tokenize_int_ge_0(num-500)}" if num > 500 and num < 600
109
+ return "ექვსას #{tokenize_int_ge_0(num-600)}" if num > 600 and num < 700
110
+ return "შვიდას #{tokenize_int_ge_0(num-700)}" if num > 700 and num < 800
111
+ return "რვაას #{tokenize_int_ge_0(num-800)}" if num > 800 and num < 900
112
+ return "ცხრაას #{tokenize_int_ge_0(num-900)}" if num > 900 and num < 1000
113
+ return "ათას #{tokenize_int_ge_0(num-1000)}" if num > 1000 and num < 2000
114
+ if num >= 2000 and num <= 999999
115
+ thousands = num/1000
116
+ rest = num - thousands * 1000
117
+ return "#{tokenize_int_ge_0(thousands)} ათას #{tokenize_int_ge_0(rest)}" if rest != 0
118
+ return "#{tokenize_int_ge_0(thousands)} ათასი" if rest == 0
119
+ end
120
+ return "მილიონ #{tokenize_int_ge_0(num-1000000)}" if num > 1000000 and num < 2000000
121
+ if num >= 2000000 and num <= 999999999
122
+ millions = num/1000000
123
+ rest = num - millions * 1000000
124
+ return "#{tokenize_int_ge_0(millions)} მილიონ #{tokenize_int_ge_0(rest)}" if rest != 0
125
+ return "#{tokenize_int_ge_0(millions)} მილიონი" if rest == 0
126
+ end
127
+ return "მილიარდ #{tokenize_int_ge_0(num-1000000000)}" if num > 1000000000 and num < 2000000000
128
+ if num >= 2000000000 and num <= 999999999999
129
+ billions = num/1000000000
130
+ rest = num - billions * 1000000000
131
+ return "#{tokenize_int_ge_0(billions)} მილიარდ #{tokenize_int_ge_0(rest)}" if rest != 0
132
+ return "#{tokenize_int_ge_0(billions)} მილიარდი"
133
+ end
134
+ return num.to_s
135
+ end
136
+
137
+ end
138
+ end
Binary file
data/lib/c12/pdf.rb ADDED
@@ -0,0 +1,40 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'prawn'
4
+
5
+ module C12
6
+ # This module is used for working with PDF.
7
+ module PDF
8
+
9
+ class Document < Prawn::Document
10
+
11
+ # Sets the current font of the document.
12
+ # Font names are predefined.
13
+ # All of them are Georgian-character friendly fonts.
14
+ #
15
+ # @param font name of the font. This may be one of
16
+ # <code>default</code>, <code>serif</code>, <code>sefit-italic</code>,
17
+ # <code>serif-bold</code>, <code>serif-bold-italic</code>.
18
+ # Value <code>nil</code> or any other value is considered as <code>default</code>.
19
+ # @param size size for the font. This parameter defaults to 10pt.
20
+ def change_font(font = :default, size = 10)
21
+ case font.to_s
22
+ when 'serif'
23
+ ff = 'DejaVuSerif'
24
+ when 'serif-italic'
25
+ ff = 'DejaVuSerif-Italic'
26
+ when 'serif-bold'
27
+ ff = 'DejaVuSerif-Bold'
28
+ when 'serif-bold-italic'
29
+ ff = 'DejaVuSerif-BoldItalic'
30
+ else
31
+ ff = 'Arial Unicode'
32
+ end
33
+ #pdf.font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
34
+ self.font File.expand_path("../pdf-assets/#{ff}.ttf", __FILE__), :size => size
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module C12
3
3
  module Commons
4
- VERSION = "0.0.1.beta2"
4
+ VERSION = "0.0.1.beta3"
5
5
  end
6
6
  end
data/lib/c12-commons.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  require 'action_controller'
4
-
5
4
  include ActionView::Helpers::NumberHelper
6
5
 
7
- require 'c12-commons/version'
8
- require 'c12-commons/ruby'
9
- require 'c12-commons/ka'
6
+ require 'c12/version'
7
+ require 'c12/core'
8
+ require 'c12/ka'
9
+ require 'c12/pdf'
@@ -83,4 +83,4 @@ test_short_month_name(10, 'ოქტ')
83
83
  test_short_month_name(11, 'ნოე')
84
84
  test_short_month_name(12, 'დეკ')
85
85
 
86
- test_full_month_name(nil, nil)
86
+ test_full_month_name(nil, nil)
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ def test_number_tokenizer(num, expected_token)
6
+ describe "#{num} is" do
7
+ specify(expected_token) { C12::KA::tokenize(num).should == expected_token }
8
+ end
9
+ end
10
+
11
+ test_number_tokenizer(-102, 'მინუს ას ორი')
12
+ test_number_tokenizer(-1, 'მინუს ერთი')
13
+ test_number_tokenizer(0, 'ნული')
14
+ test_number_tokenizer(1, 'ერთი')
15
+ test_number_tokenizer(999, 'ცხრაას ოთხმოცდა ცხრამეტი')
16
+ test_number_tokenizer(-9999, 'მინუს ცხრა ათას ცხრაას ოთხმოცდა ცხრამეტი')
@@ -0,0 +1,14 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Simple PDF generation' do
6
+ before(:all) do
7
+ C12::PDF::Document.generate 'tmp/example.pdf' do |pdf|
8
+ pdf.change_font
9
+ pdf.text 'დიმიტრი ყურაშვილი'
10
+ end
11
+ end
12
+ specify { File.exists?('tmp/example.pdf').should == true }
13
+ specify { File.zero?('tmp/example.pdf').should == false }
14
+ end
@@ -41,4 +41,4 @@ end
41
41
  test_number_formatting(1, 0, '1')
42
42
  test_number_formatting(1000, 0, '1 000')
43
43
  test_number_formatting(1000, 3, '1 000,000')
44
- test_number_formatting(123456.789, 2, '123 456,79')
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.beta2
4
+ version: 0.0.1.beta3
5
5
  prerelease: 6
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-01 00:00:00.000000000 Z
12
+ date: 2012-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70293265727240 !ruby/object:Gem::Requirement
16
+ requirement: &70164365351300 !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: *70293265727240
24
+ version_requirements: *70164365351300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simplecov
27
- requirement: &70293265726820 !ruby/object:Gem::Requirement
27
+ requirement: &70164365350680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70293265726820
35
+ version_requirements: *70164365350680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: actionpack
38
- requirement: &70293265726200 !ruby/object:Gem::Requirement
38
+ requirement: &70164365350060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,8 +43,19 @@ dependencies:
43
43
  version: '3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70293265726200
47
- description: Common functionality for Ruby code
46
+ version_requirements: *70164365350060
47
+ - !ruby/object:Gem::Dependency
48
+ name: prawn
49
+ requirement: &70164365349560 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70164365349560
58
+ description: Simple functionality used in my projects
48
59
  email:
49
60
  - dimitri@c12.ge
50
61
  executables: []
@@ -58,13 +69,21 @@ files:
58
69
  - Rakefile
59
70
  - c12-commons.gemspec
60
71
  - lib/c12-commons.rb
61
- - lib/c12-commons/ka.rb
62
- - lib/c12-commons/ruby.rb
63
- - lib/c12-commons/version.rb
72
+ - lib/c12/core.rb
73
+ - lib/c12/ka.rb
74
+ - lib/c12/pdf-assets/Arial Unicode.ttf
75
+ - lib/c12/pdf-assets/DejaVuSerif-Bold.ttf
76
+ - lib/c12/pdf-assets/DejaVuSerif-BoldItalic.ttf
77
+ - lib/c12/pdf-assets/DejaVuSerif-Italic.ttf
78
+ - lib/c12/pdf-assets/DejaVuSerif.ttf
79
+ - lib/c12/pdf.rb
80
+ - lib/c12/version.rb
64
81
  - spec/c12-commons/month_spec.rb
82
+ - spec/c12-commons/number_spec.rb
83
+ - spec/c12-commons/pdf_spec.rb
65
84
  - spec/c12-commons/ruby_spec.rb
66
85
  - spec/spec_helper.rb
67
- homepage: ''
86
+ homepage: http://c12.ge
68
87
  licenses: []
69
88
  post_install_message:
70
89
  rdoc_options: []
@@ -87,9 +106,11 @@ rubyforge_project: c12-commons
87
106
  rubygems_version: 1.8.15
88
107
  signing_key:
89
108
  specification_version: 3
90
- summary: Common functions
109
+ summary: Simple functions
91
110
  test_files:
92
111
  - spec/c12-commons/month_spec.rb
112
+ - spec/c12-commons/number_spec.rb
113
+ - spec/c12-commons/pdf_spec.rb
93
114
  - spec/c12-commons/ruby_spec.rb
94
115
  - spec/spec_helper.rb
95
116
  has_rdoc:
@@ -1,43 +0,0 @@
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