encoding-kawai 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,15 +3,15 @@ EncodingKawai - little sintax sugar for ruby force_encoding, also working on 1.8
3
3
  gem 'encoding-kawai'
4
4
 
5
5
  ```ruby
6
- str._utf8 # str.respond_to?(:force_encoding) ? str.force_encoding('utf-8') : str
7
- str._binary # str.respond_to?(:force_encoding) ? str.force_encoding('binary') : str
6
+ str.utf8! # str.respond_to?(:force_encoding) ? str.force_encoding('utf-8') : str
7
+ str.binary! # str.respond_to?(:force_encoding) ? str.force_encoding('binary') : str
8
8
  ```
9
9
 
10
10
  Extend object.
11
11
  ```ruby
12
12
  require 'encoding-kawai/object'
13
13
 
14
- [str1, str2]._utf8
15
- {str1 => str2}._utf8
14
+ [str1, str2].utf8!
15
+ {str1 => str2}.utf8!
16
16
  ...
17
17
  ```
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{encoding-kawai}
5
- s.version = "0.2"
5
+ s.version = "0.3"
6
6
 
7
7
  s.authors = ["Makarchev K"]
8
8
 
@@ -1,11 +1,11 @@
1
1
  if RUBY_VERSION < '1.9'
2
2
 
3
3
  class String
4
- def _utf8
4
+ def utf8!
5
5
  self
6
6
  end
7
7
 
8
- def _binary
8
+ def binary!
9
9
  self
10
10
  end
11
11
  end
@@ -13,11 +13,11 @@ if RUBY_VERSION < '1.9'
13
13
  else
14
14
 
15
15
  class String
16
- def _utf8
16
+ def utf8!
17
17
  self.force_encoding('utf-8')
18
18
  end
19
19
 
20
- def _binary
20
+ def binary!
21
21
  self.force_encoding('binary')
22
22
  end
23
23
  end
@@ -25,11 +25,11 @@ else
25
25
  end
26
26
 
27
27
  class NilClass
28
- def _utf8
28
+ def utf8!
29
29
  self
30
30
  end
31
31
 
32
- def _binary
32
+ def binary!
33
33
  self
34
34
  end
35
35
  end
@@ -1,44 +1,44 @@
1
1
  class Object
2
- def _utf8
2
+ def utf8!
3
3
  self
4
4
  end
5
5
 
6
- def _binary
6
+ def binary!
7
7
  self
8
8
  end
9
9
  end
10
10
 
11
11
  if RUBY_VERSION >= '1.9'
12
12
  class Array
13
- def _utf8
14
- map { |a| a._utf8 }
13
+ def utf8!
14
+ map { |a| a.utf8! }
15
15
  end
16
16
 
17
- def _binary
18
- map { |a| a._binary }
17
+ def binary!
18
+ map { |a| a.binary! }
19
19
  end
20
20
  end
21
21
 
22
22
  class Regexp
23
- def _utf8
24
- Regexp.new(to_s._utf8)
23
+ def utf8!
24
+ Regexp.new(to_s.utf8!)
25
25
  end
26
26
 
27
- def _binary
28
- Regexp.new(to_s._binary)
27
+ def binary!
28
+ Regexp.new(to_s.binary!)
29
29
  end
30
30
  end
31
31
 
32
32
  class Hash
33
- def _utf8
33
+ def utf8!
34
34
  {}.tap{|h|
35
- keys.each { |k| h[k.frozen? ? k.dup._utf8 : k._utf8] = self[k]._utf8 }
35
+ keys.each { |k| h[k.frozen? ? k.dup.utf8! : k.utf8!] = self[k].utf8! }
36
36
  }
37
37
  end
38
38
 
39
- def _binary
39
+ def binary!
40
40
  {}.tap{|h|
41
- keys.each { |k| h[k.frozen? ? k.dup._binary : k._binary] = self[k]._binary }
41
+ keys.each { |k| h[k.frozen? ? k.dup.binary! : k.binary!] = self[k].binary! }
42
42
  }
43
43
  end
44
44
  end
@@ -11,12 +11,12 @@ describe "encoding-kawai" do
11
11
  %w{utf8 binary}.each do |enc|
12
12
  OBJS.each do |obj|
13
13
  it "should word for each object to code with #{enc} on obj: #{obj.inspect}" do
14
- obj.send("_#{enc}").should == obj
14
+ obj.send("#{enc}!").should == obj
15
15
  end
16
16
  end
17
17
 
18
18
  it "should word for each object to code with #{enc} on obj: #{H.inspect}" do
19
- H.send("_#{enc}").should == H
19
+ H.send("#{enc}!").should == H
20
20
  end
21
21
  end
22
22
 
@@ -25,19 +25,19 @@ describe "encoding-kawai" do
25
25
  %w{utf8 binary}.each do |enc|
26
26
  OBJS.each do |obj|
27
27
  it "should word for each object to code with #{enc} on obj: #{obj.inspect}" do
28
- obj.send("_#{enc}").should == obj
28
+ obj.send("#{enc}!").should == obj
29
29
  end
30
30
  end
31
31
 
32
32
  it "should word for each object to code with #{enc} on obj: #{H.inspect}" do
33
33
  str = enc == 'utf8' ? "бла".force_encoding('utf-8') : "бла".force_encoding('binary')
34
- H.send("_#{enc}").should == {:bla => 'bla', str => 1}
34
+ H.send("#{enc}!").should == {:bla => 'bla', str => 1}
35
35
  end
36
36
 
37
37
  it "should set encoding" do
38
38
  str = "бла"
39
39
  str.encoding.name.should == "UTF-8"
40
- str.send("_#{enc}")
40
+ str.send("#{enc}!")
41
41
  if enc == 'utf8'
42
42
  str.encoding.name.should == 'UTF-8'
43
43
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encoding-kawai
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
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-09-03 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  segments:
76
76
  - 0
77
- hash: -334021939
77
+ hash: -951121923
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  none: false
80
80
  requirements:
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  segments:
85
85
  - 0
86
- hash: -334021939
86
+ hash: -951121923
87
87
  requirements: []
88
88
  rubyforge_project:
89
89
  rubygems_version: 1.8.24