enco 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
6
+ doc/
7
+ log/*.log
8
+ /tmp/
9
+ tmp/
10
+ db/*.sqlite3
11
+ /coverage
12
+ /coverage.data
13
+ /.yardoc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - ruby-head
@@ -0,0 +1,161 @@
1
+ Contributing to Enco
2
+ ==========================
3
+ Enco is an open source project. Anyone can use the code, but more importantly, anyone can contribute. This is a
4
+ group effort and we value your input. Please consider making a contribution to help improve the Enco. This
5
+ guide covers:
6
+
7
+ * How to file a ticket when you discover a bug
8
+ * How to contribute fixes and improvements to the core
9
+ * Information on how to improve the documentation
10
+
11
+ 1. Who can Contribute?
12
+ ----------------------
13
+ Enco is an open source project and as such contributions are always welcome. Our community is one which
14
+ encourages involvement from all developers regardless of their ability level. We ask that you be patient with the
15
+ other members of the community and maintain a respectful attitude towards other people’s work. Open source is a
16
+ great way to learn a new technology so don’t be afraid to jump right in, even if you are new to Ruby/Rails.
17
+
18
+ 2. Before you Contribute
19
+ ------------------------
20
+ Open source projects tend to be a collaborative effort. Since many people are relying upon Enco for their real
21
+ world applications, changes to the code can have major implications. Before you write a bug fix or code a new
22
+ feature, you should find out if anybody is interested in your proposed change. You may find that the thing you’re
23
+ trying to “fix” is actually desired behavior. You might also discover that someone else is working on it. Either
24
+ way you can save yourself valuable time by announcing your intentions before starting work.
25
+
26
+ ### 2.1. Notification via Ticket
27
+
28
+ You can also search existing bug reports/issues and file a new one if you do not find an issue relevant to your
29
+ proposed change. See Filing an Issue for more details.
30
+
31
+ The important thing is that you communicate your intention in advance of doing a lot of work. Simple bug fixes and
32
+ non-controversial changes do not require this approach but you can save some time by suggesting an improvement and
33
+ having it rejected before you write a bunch of the code.
34
+
35
+ 3. Filing an Issue
36
+ -----------------
37
+ If you would like to file a bug report, please create an issue in our Github Issues Tracker. You should do a basic
38
+ search of the issues database before creating a new issue to ensure that you are not creating a duplicate issue.
39
+
40
+ Please do not assign labels or create new labels to your issue. We will assign the appropriate labels to ensure your
41
+ ticket is handled in the appropriate manner.
42
+
43
+ ### 3.1. Providing a Patch
44
+
45
+ If you are filing and issue and supplying a patch at the same time, please file a Pull Request instead. The pull
46
+ request will also create an issue at the same time but its superior to just creating an issue because the code and
47
+ issue can be linked.
48
+
49
+ If the ticket already exists, however, and you want to supply a patch after the fact,
50
+ you can simply reference the issue number in your commit message. For example, if your commit fixed issue #123 you
51
+ could use the following commit message:
52
+
53
+ Fixed a problem with Facebook authentication.
54
+
55
+ [Fixes #123]
56
+ Github will automatically detect this commit message when you push it and link the issue. Please see the detailed
57
+ Github Issues blog post for more details.
58
+
59
+ ### 3.2. Feature Requests
60
+
61
+ We’re interested in hearing your ideas for new features but creating feature requests in the Issue Tracker is not
62
+ the proper way to ask for a feature. A feature request is any idea you have to improve the software experience that
63
+ is not strictly related to a bug or error of omission.
64
+
65
+ Feature requests that are accompanied by source code are always welcome. In this case you should read the next
66
+ section on Creating a Pull Request.
67
+
68
+ Feature requests without accompanying code will be closed. We simply cannot respond efficiently to feature requests
69
+ through our Issue Tracker. If you want to suggest a feature, please use the mailing list or the user voice forum.
70
+
71
+ ### 3.3. How We Prioritize Issues
72
+
73
+ We try our best to respond to all of the questions and issues our users have. We use the following criteria to
74
+ prioritize issues:
75
+
76
+ * Does this bug effect the latest stable release?
77
+ * Is there a patch associated with the issue?
78
+ * Is ther a test included in the patch?
79
+ * Has someone else verified the bug?
80
+ * Are there details on how to reproduce the problem?
81
+ * We give highest priority to issues where the answer is “yes” to all of these questions. Next highest priority is for
82
+ issues that answer “yes” to most of these questions, particularly the first few criteria.
83
+
84
+ You need to include a brief description of the problem and simple steps needed to reproduce it. If you fail to
85
+ supply this minimum level of information your issue will likely be ignored.
86
+
87
+
88
+ 4. Creating a Pull Request
89
+ --------------------------
90
+
91
+ If you are going to contribute code to the Enco project, the best mechanism for doing this is to create a pull
92
+ request in Github. If you’re unfamiliar with the general concept of pull requests you may want to read more on pull
93
+ requests in Github.
94
+
95
+ If your code is associated with an existing issue then you can provide a patch instead of creating a pull request.
96
+
97
+ ### 4.1. Creating a Fork
98
+
99
+ The official Enco source code is maintained in Github under the AlexParamonov/enco
100
+
101
+ You simply need to “fork” the project and then start hacking.
102
+
103
+ See the Github guide on creating forks for more details.
104
+
105
+ ### 4.2. Topic Branches
106
+
107
+ Git branches are “cheap.” Creating branches in Git is incredibly easy and its an ideal way to isolate a specific set
108
+ of changes. You may be fixing several things at one time but by keeping your changes isolated it will help us to
109
+ find and apply only the changes we’re interested in. You should create a clean branch based on the latest
110
+ enco/master when doing this. It is important you follow these steps exactly,
111
+ it will prevent you from accidentally including unrelated changes from your local repository into the branch.
112
+
113
+ For example, if we were submitting a patch to fix an issue with the CSS in the flash error message you could create
114
+ a branch as follows:
115
+
116
+ $ git remote add upstream git://github.com/AlexParamonov/enco.git
117
+ $ git fetch upstream
118
+ $ git checkout -b fix-css-for-error-flash --track upstream/master
119
+
120
+ The fetch command will grab all of the latest commits from the Enco master branch. Don’t worry,
121
+ it doesn’t alter your working repository in a harmful way. The track part of the command will tell git that this
122
+ branch should track with the remote version of the upstream master. This is another way of saying that the branch
123
+ should be based on a clean copy of the latest official source code (without any of your unrelated local changes.)
124
+
125
+ You can then do work locally on this topic branch and push it up to your Github fork when you are done. So in our
126
+ previous example we do something like:
127
+
128
+ $ git push origin fix-css-for-error-flash
129
+
130
+ Of course if you want the fix for yourself to use in your own local code you should probably merge it down to your
131
+ own personal master branch that you’re using for development
132
+
133
+ $ git checkout master
134
+ $ git merge fix-css-for-error-flash
135
+
136
+ You should probably also clean up after yourself a little. The branch has been pushed to Github and you’ve merged it
137
+ locally so you don’t really need a local copy of the branch laying around.
138
+
139
+ $ git branch -D fix-css-for-error-flash
140
+
141
+ ### 4.3. Including a Test
142
+
143
+ Ideally your pull request will also include a test that verifies a bug (or the absence of the new feature) before
144
+ your fix and also verifies proper functionality when you are finished. Please read the Testing Guide for more
145
+ information on writing and running your tests.
146
+
147
+ Pull requests with tests are given top priority. Failure to include a test will likely delay acceptance of your patch.
148
+
149
+ ### 4.4. Creating the Pull Request
150
+
151
+ Once your code is ready to go and you have pushed your topic branch to Github then you are ready to create the pull
152
+ request and notify the Enco team that your contribution is ready. You do this by browsing your project in
153
+ Github and changing to the topic branch you just pushed. Once you are on the topic branch simply create a pull
154
+ request by pressing the “Pull Request” button.
155
+
156
+ The Github guide on pull requests describes this in more detail with screenshots if you’re still confused on this
157
+ part.
158
+
159
+ 5 Contributing to the Documentation
160
+ -----------------------------------
161
+ Improvements to the documentation is encouraged.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in enco.gemspec
4
+ gemspec
@@ -0,0 +1,7 @@
1
+ 0.1.0
2
+ =====
3
+ Main functionality implemented
4
+
5
+ 0.0.1
6
+ =====
7
+ Initial release. Add README, LICENSE, .gitignore, etc.
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Alexander N Paramonov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ Enco
2
+ ==========
3
+ Enco will convert any string to utf-8
4
+
5
+ Installation
6
+ ------------
7
+ gem install enco
8
+
9
+ Usage
10
+ -----
11
+ It is simple. Just call
12
+
13
+ my_utf8_string = Enco.to_utf8 any_string
14
+
15
+ It will return non string objects back:
16
+
17
+ Enco.to_utf8(not_a_string) === not_a_string
18
+
19
+ works correctly with frozen strings. If you dont want to convert frozen string, pass :ignore_frozen => true and Enco
20
+ will ignore that string:
21
+
22
+ Enco.to_utf8 any_string.frozen, :ignore_frozen => true # returns frozen string
23
+ Enco.to_utf8 any_string.frozen # returns dup of any_string, converted to utf-8
24
+
25
+ ### Plugins
26
+ Add
27
+
28
+ require 'enco/string_to_utf8'
29
+
30
+ end you'll get
31
+
32
+ "any string".to_utf8
33
+ method that accept same options as
34
+
35
+ Enco.to_utf8 "any string"
36
+
37
+
38
+ Requirements
39
+ ------------
40
+
41
+ * Ruby 1.9
42
+ * rchardet19
43
+
44
+ Compatibility
45
+ -------------
46
+ tested with Ruby
47
+
48
+ * 1.9.2
49
+ * 1.9.3
50
+ * ruby-head
51
+
52
+ see [build history](http://travis-ci.org/#!/AlexParamonov/enco/builds)
53
+
54
+ Contributing
55
+ -------------
56
+ see [contributing guide](http://github.com/AlexParamonov/enco/blob/master/CONTRIBUTING.md)
57
+
58
+ Copyright
59
+ ---------
60
+ Copyright © 2011 Alexander N Paramonov.
61
+ Released under the MIT License. See the LICENSE file for further details.
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ # GEMS
3
+ require "bundler/gem_tasks"
4
+
5
+ # SPECS
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+ #Rake::Task["spec"].execute
12
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "enco/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "enco"
7
+ s.version = Enco::VERSION
8
+ s.authors = ["Alexander Paramonov"]
9
+ s.email = ["alexander.n.paramonov@gmail.com"]
10
+ s.homepage = "http://github.com/AlexParamonov/enco"
11
+ s.summary = %q{Nice utf8 converter}
12
+ s.description = %q{Enco will convert any string to utf-8.}
13
+
14
+ s.rubyforge_project = "enco"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec", ">= 2.6"
23
+ s.add_development_dependency "rake"
24
+ s.add_runtime_dependency "rchardet19"
25
+ #s.add_runtime_dependency "activesupport"
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'rchardet19'
2
+
3
+ # Enco will convert any string to utf-8
4
+ # Just call Enco.to_utf8 any_string
5
+ # It will return non string objects back: Enco.to_utf8(not_a_string) === not_a_string
6
+ module Enco
7
+ # @param [String] string
8
+ # @param [Hash] options
9
+ # @option options [Boolean] :ignore_frozen
10
+ def self.to_utf8 string, options = {}
11
+ return string unless string.is_a? String
12
+ if string.frozen?
13
+ return string if true == options[:ignore_frozen]
14
+ string = string.dup
15
+ end
16
+
17
+ cd = ::CharDet.detect(string, :silent => true)
18
+
19
+ if cd.confidence > 0.5 then
20
+ string.encode('utf-8', cd.encoding, :invalid => :replace)
21
+ else
22
+ force_to_utf8 string
23
+ end
24
+ end
25
+
26
+ private
27
+ def self.force_to_utf8 string
28
+ require 'iconv'
29
+ ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
30
+ ic.iconv(string + ' ')[0..-2]
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ require "enco"
2
+ class String
3
+ def to_utf8 *args
4
+ Enco.to_utf8 self, *args
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Enco
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,86 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ # TODO add more Test cases
5
+ describe Enco do
6
+ before(:each) do
7
+ @simple_string = %Q{test string\nin }
8
+ @cyrillic_string = %Q{тестовая строка\nin }
9
+ end
10
+ describe "#to_utf8" do
11
+ describe "argument is" do
12
+ context "a string in" do
13
+ specify "UTF-8 encoding" do
14
+ result = Enco.to_utf8(string_in 'UTF-8')
15
+ result.should eq @cyrillic_string + "UTF-8\n"
16
+ result.encoding.to_s.should == "UTF-8"
17
+ end
18
+
19
+ specify "KOI8-R encoding" do
20
+ result = Enco.to_utf8(string_in 'KOI8-R')
21
+ result.should eq @cyrillic_string + "KOI8-R\n"
22
+ result.encoding.to_s.should == "UTF-8"
23
+ end
24
+
25
+ specify "CP866 encoding" do
26
+ result = Enco.to_utf8(string_in 'CP866')
27
+ result.should eq @cyrillic_string + "CP866\n"
28
+ result.encoding.to_s.should == "UTF-8"
29
+ end
30
+
31
+ specify "ISO-8859-15 encoding" do
32
+ result = Enco.to_utf8(string_in 'ISO-8859-15')
33
+ result.should eq @simple_string + "ISO-8859-15\n"
34
+ result.encoding.to_s.should == "UTF-8"
35
+ end
36
+
37
+ specify "WINDOWS-1251 encoding" do
38
+ result = Enco.to_utf8(string_in 'WINDOWS-1251')
39
+ result.should eq @cyrillic_string + "WINDOWS-1251\n"
40
+ result.encoding.to_s.should == "UTF-8"
41
+ end
42
+ end
43
+
44
+ context "a frozen string" do
45
+ before(:each) do
46
+ @test_string = "test string".force_encoding "ISO-8859-15"
47
+ end
48
+
49
+ it "should perform conversion" do
50
+ result = Enco.to_utf8 @test_string.freeze
51
+ result.encoding.to_s.should == "UTF-8"
52
+ end
53
+
54
+ it "should not change input string" do
55
+ Enco.to_utf8 @test_string.freeze
56
+
57
+ @test_string.encoding.to_s.should == "ISO-8859-15"
58
+ end
59
+
60
+ context "ignore_frozen flag set to true" do
61
+ it "should return string itself" do
62
+ result = Enco.to_utf8 @test_string.freeze, :ignore_frozen => true
63
+ result.should eq @test_string
64
+ result.encoding.to_s.should == "ISO-8859-15"
65
+ end
66
+ end
67
+ end
68
+
69
+ context "not a string" do
70
+ describe "should ignore argument and return it back for" do
71
+ specify "nil" do
72
+ result = Enco.to_utf8 nil
73
+ result.should be_nil
74
+ end
75
+
76
+ specify "object" do
77
+ object = Object.new
78
+ result = Enco.to_utf8 object
79
+ result.should eql object
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ ��⮢�� ��ப�
2
+ in CP866
@@ -0,0 +1,2 @@
1
+ test string
2
+ in ISO-8859-15
@@ -0,0 +1,2 @@
1
+ �������� ������
2
+ in KOI8-R
@@ -0,0 +1,2 @@
1
+ тестовая строка
2
+ in UTF-8
@@ -0,0 +1,2 @@
1
+ �������� ������
2
+ in WINDOWS-1251
@@ -0,0 +1,2 @@
1
+ require "enco"
2
+ Dir[File.dirname(File.expand_path(__FILE__)) + "/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "spec_helper"
3
+ require "enco/string_to_utf8"
4
+
5
+ # TODO add more Test cases
6
+ describe String do
7
+ describe "#to_utf8" do
8
+ before(:each) do
9
+ @test_string = "test string"
10
+ end
11
+ it "should delegate to Enco#to_utf8" do
12
+ Enco.should_receive(:to_utf8).with(@test_string).once
13
+
14
+ @test_string.to_utf8
15
+ end
16
+
17
+ it "should pass options to Enco#to_utf8" do
18
+ Enco.should_receive(:to_utf8).with(@test_string, :some_param => true).once
19
+
20
+ @test_string.to_utf8 :some_param => true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ def string_in(encoding)
2
+ File.read(File.dirname(File.expand_path(__FILE__)) << "/../fixtures/" << encoding.upcase, :encoding => "BINARY")
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Paramonov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &16372380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *16372380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &16371400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *16371400
36
+ - !ruby/object:Gem::Dependency
37
+ name: rchardet19
38
+ requirement: &16370800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *16370800
47
+ description: Enco will convert any string to utf-8.
48
+ email:
49
+ - alexander.n.paramonov@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - .travis.yml
57
+ - CONTRIBUTING.md
58
+ - Gemfile
59
+ - HISTORY.md
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - enco.gemspec
64
+ - lib/enco.rb
65
+ - lib/enco/string_to_utf8.rb
66
+ - lib/enco/version.rb
67
+ - spec/enco_spec.rb
68
+ - spec/fixtures/CP866
69
+ - spec/fixtures/ISO-8859-15
70
+ - spec/fixtures/KOI8-R
71
+ - spec/fixtures/UTF-8
72
+ - spec/fixtures/WINDOWS-1251
73
+ - spec/spec_helper.rb
74
+ - spec/string_to_utf8_spec.rb
75
+ - spec/support/encoding_helper.rb
76
+ homepage: http://github.com/AlexParamonov/enco
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project: enco
96
+ rubygems_version: 1.8.12
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Nice utf8 converter
100
+ test_files: []