encoding-kawai 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ log
2
+ TODO
3
+ locks
4
+ *.gem
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Makarchev K
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ EncodingKawai - little sintax sugar for ruby force_encoding, also working on 1.8.7.
2
+
3
+ gem 'encoding-kawai'
4
+
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
8
+ ```
9
+
10
+ Extend object.
11
+ ```ruby
12
+ require 'encoding-kawai/object'
13
+
14
+ [str1, str2]._utf8
15
+ {str1 => str2}._utf8
16
+ ...
17
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ task :default => :spec
8
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{encoding-kawai}
5
+ s.version = "0.1"
6
+
7
+ s.authors = ["Makarchev K"]
8
+
9
+ s.description = %q{EncodingKawai - little sintax sugar for ruby force_encoding, also working on 1.8.7.}
10
+ s.summary = %q{Encodingkawai - little sintax sugar for ruby force_encoding, also working on 1.8.7.}
11
+
12
+ s.email = %q{kostya27@gmail.com}
13
+ #s.homepage = %q{http://github.com/kostya/encoding-kawai}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rspec"
21
+ s.add_development_dependency "rake"
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ if RUBY_VERSION < '1.9'
2
+
3
+ class String
4
+ def _utf8
5
+ self
6
+ end
7
+
8
+ def _binary
9
+ self
10
+ end
11
+ end
12
+
13
+ else
14
+
15
+ class String
16
+ def _utf8
17
+ self.force_encoding('utf-8')
18
+ end
19
+
20
+ def _binary
21
+ self.force_encoding('binary')
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,46 @@
1
+ class Object
2
+ def _utf8
3
+ self
4
+ end
5
+
6
+ def _binary
7
+ self
8
+ end
9
+ end
10
+
11
+ if RUBY_VERSION >= '1.9'
12
+ class Array
13
+ def _utf8
14
+ map { |a| a._utf8 }
15
+ end
16
+
17
+ def _binary
18
+ map { |a| a._binary }
19
+ end
20
+ end
21
+
22
+ class Regexp
23
+ def _utf8
24
+ Regexp.new(to_s._utf8)
25
+ end
26
+
27
+ def _binary
28
+ Regexp.new(to_s._binary)
29
+ end
30
+ end
31
+
32
+ class Hash
33
+ def _utf8
34
+ {}.tap{|h|
35
+ keys.each { |k| h[k.frozen? ? k.dup._utf8 : k._utf8] = self[k]._utf8 }
36
+ }
37
+ end
38
+
39
+ def _binary
40
+ {}.tap{|h|
41
+ keys.each { |k| h[k.frozen? ? k.dup._binary : k._binary] = self[k]._binary }
42
+ }
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,49 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ OBJS = ["bla", 'бла', ['bla', 'бла']]
5
+ H = {:bla => 'bla', 'бла' => 1}
6
+
7
+ describe "encoding-kawai" do
8
+
9
+ if RUBY_VERSION < '1.9'
10
+
11
+ %w{utf8 binary}.each do |enc|
12
+ OBJS.each do |obj|
13
+ it "should word for each object to code with #{enc} on obj: #{obj.inspect}" do
14
+ obj.send("_#{enc}").should == obj
15
+ end
16
+ end
17
+
18
+ it "should word for each object to code with #{enc} on obj: #{H.inspect}" do
19
+ H.send("_#{enc}").should == H
20
+ end
21
+ end
22
+
23
+ else
24
+
25
+ %w{utf8 binary}.each do |enc|
26
+ OBJS.each do |obj|
27
+ it "should word for each object to code with #{enc} on obj: #{obj.inspect}" do
28
+ obj.send("_#{enc}").should == obj
29
+ end
30
+ end
31
+
32
+ it "should word for each object to code with #{enc} on obj: #{H.inspect}" do
33
+ str = enc == 'utf8' ? "бла".force_encoding('utf-8') : "бла".force_encoding('binary')
34
+ H.send("_#{enc}").should == {:bla => 'bla', str => 1}
35
+ end
36
+
37
+ it "should set encoding" do
38
+ str = "бла"
39
+ str.encoding.name.should == "UTF-8"
40
+ str.send("_#{enc}")
41
+ if enc == 'utf8'
42
+ str.encoding.name.should == 'UTF-8'
43
+ else
44
+ str.encoding.name.should == 'ASCII-8BIT'
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rubygems'
3
+ require "bundler/setup"
4
+
5
+ require 'encoding-kawai'
6
+ require 'encoding-kawai/object'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encoding-kawai
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Makarchev K
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-09-02 00:00:00 +04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ prerelease: false
31
+ type: :development
32
+ requirement: *id001
33
+ name: rspec
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ prerelease: false
45
+ type: :development
46
+ requirement: *id002
47
+ name: rake
48
+ description: EncodingKawai - little sintax sugar for ruby force_encoding, also working on 1.8.7.
49
+ email: kostya27@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - .gitignore
58
+ - Gemfile
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - encoding-kawai.gemspec
63
+ - lib/encoding-kawai.rb
64
+ - lib/encoding-kawai/object.rb
65
+ - spec/encoding-kawai_spec.rb
66
+ - spec/spec_helper.rb
67
+ has_rdoc: true
68
+ homepage:
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.4.2
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Encodingkawai - little sintax sugar for ruby force_encoding, also working on 1.8.7.
101
+ test_files: []
102
+