gaigo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
File without changes
data/CHANGELOG CHANGED
@@ -0,0 +1,3 @@
1
+ == 0.0.2
2
+
3
+ * Alfa release.
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
File without changes
File without changes
data/Rakefile CHANGED
File without changes
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["addagger@gmail.com"]
11
11
  gem.homepage = %q{http://vkvon.ru/projects/gaigo}
12
12
  gem.description = %q{76 world's languages and codes}
13
- gem.summary = %q{World's languages/countries, locale attribute for Rails' models}
13
+ gem.summary = %q{World's languages/countries, localization for Rails' models}
14
14
 
15
15
  gem.rubyforge_project = "gaigo"
16
16
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,7 +9,7 @@ module Gaigo
9
9
  def initialize(en, code, native)
10
10
  @en = en
11
11
  @code = code
12
- @native = native
12
+ @native = native.encode('UTF-8')
13
13
  freeze
14
14
  end
15
15
  def to_s
@@ -19,7 +19,7 @@ module Gaigo
19
19
  en.downcase.gsub(/\W|\d/,"_")
20
20
  end
21
21
  end
22
-
22
+
23
23
  def add_lang(attributes)
24
24
  self << Lang.new(*attributes)
25
25
  end
@@ -27,11 +27,27 @@ module Gaigo
27
27
  def get(code)
28
28
  self.find {|i| i.code == code.to_s}
29
29
  end
30
+
31
+ def get_by_method(method)
32
+ self.find {|i| i.to_method == method.to_s}
33
+ end
34
+
35
+ def get_by_native(name)
36
+ self.find {|i| i.native.mb_chars.downcase.to_s == name.encode('UTF-8').mb_chars.downcase.to_s}
37
+ end
38
+
39
+ def get_by_en(name)
40
+ self.find {|i| i.en.downcase == name.downcase.to_s}
41
+ end
30
42
 
43
+ def get_by_name(name)
44
+ get_by_native(name)||get_by_english(name)
45
+ end
46
+
31
47
  def codes
32
48
  self.map {|i| i.code}
33
49
  end
34
-
50
+
35
51
  def en
36
52
  self.map {|i| i.en}
37
53
  end
@@ -39,7 +55,19 @@ module Gaigo
39
55
  def native
40
56
  self.map {|i| i.native}
41
57
  end
42
-
58
+
59
+ def validate_codes(*args)
60
+ options = args.extract_options!
61
+ codes = self.codes
62
+ args.map(&:to_s).select do |code|
63
+ if code.to_s.in?(codes)
64
+ true
65
+ else
66
+ options[:raise] == true ? raise(Exception, "Invalid code: :#{code}") : false
67
+ end
68
+ end
69
+ end
70
+
43
71
  def copy(*locale_codes)
44
72
  if locale_codes.any?
45
73
  Langs.new.tap do |new_langs|
File without changes
File without changes
@@ -13,12 +13,18 @@ module Gaigo
13
13
  end
14
14
 
15
15
  def locale=(value)
16
- super(check_locale_code(value))
16
+ code = check_locale_code(value)
17
+ self._locales.validate_codes(code, :raise => true)
18
+ super(code)
17
19
  end
18
20
 
19
21
  def lang
20
22
  LANGS.get(locale)
21
23
  end
22
24
 
25
+ def lang_method
26
+ lang.try(:to_method)
27
+ end
28
+
23
29
  end
24
30
  end
File without changes
@@ -29,7 +29,7 @@ module Gaigo
29
29
 
30
30
  if block_given? #
31
31
  yield defaults #
32
- end #
32
+ end #
33
33
 
34
34
  defaults << :"attributes.#{attribute}"
35
35
  defaults << options.delete(:default) if options[:default]
@@ -20,7 +20,7 @@ module Gaigo
20
20
 
21
21
  if block_given? #
22
22
  yield defaults #
23
- end #
23
+ end #
24
24
 
25
25
  defaults << options.delete(:default) if options[:default]
26
26
 
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Gaigo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project: gaigo
90
- rubygems_version: 1.8.24
90
+ rubygems_version: 1.8.25
91
91
  signing_key:
92
92
  specification_version: 3
93
- summary: World's languages/countries, locale attribute for Rails' models
93
+ summary: World's languages/countries, localization for Rails' models
94
94
  test_files: []