enco 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,12 +2,21 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- .idea/
5
+ .idea/*
6
6
  doc/
7
- log/*.log
8
- /tmp/
9
- tmp/
7
+ log/*
8
+ tmp/*
10
9
  db/*.sqlite3
11
10
  /coverage
12
11
  /coverage.data
13
12
  /.yardoc
13
+ .rvmrc
14
+
15
+ ## generic files to ignore
16
+ *~
17
+ *.lock
18
+ *.DS_Store
19
+ *.swp
20
+ *.out
21
+ *.swo
22
+ *.md.html
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.1.1
2
+ =====
3
+ Removed special cases for frozen string.
4
+ Enco does not touch input string at all from now.
5
+
1
6
  0.1.0
2
7
  =====
3
8
  Main functionality implemented
data/LICENSE CHANGED
@@ -1,7 +1,16 @@
1
1
  Copyright (c) 2011 Alexander N Paramonov
2
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:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ documentation files (the "Software"), to deal in the Software without restriction,
5
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
7
+ subject to the following conditions:
4
8
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ Software.
6
11
 
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.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Enco
2
2
  ==========
3
- Enco will convert any string to utf-8
3
+ Enco will convert any string to utf-8, based on original string encoding.
4
4
 
5
5
  Installation
6
6
  ------------
@@ -12,27 +12,26 @@ It is simple. Just call
12
12
 
13
13
  my_utf8_string = Enco.to_utf8 any_string
14
14
 
15
- It will return non string objects back:
15
+ If you pass something other, than a string, it'll return non string objects back:
16
16
 
17
- Enco.to_utf8(not_a_string) === not_a_string
17
+ Enco.to_utf8(not_a_string) === not_a_string # true
18
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:
19
+ Enco does not touch input string, so you may pass frozen strings to it and it'll handle them correctly.
21
20
 
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
21
+ frozen_string = "hi there!".frozen
22
+ Enco.to_utf8 frozen_string # utf-8 analog of frozen_string
24
23
 
25
24
  ### Plugins
26
25
  Add
27
26
 
28
27
  require 'enco/string_to_utf8'
29
28
 
30
- end you'll get
29
+ and you'll get #to_utf-8 method on String objects:
31
30
 
32
- "any string".to_utf8
33
- method that accept same options as
31
+ "hi there!".to_utf8
32
+ It delegates to Enco.to_utf8 and accepts same options as
34
33
 
35
- Enco.to_utf8 "any string"
34
+ Enco.to_utf8 "hi there!"
36
35
 
37
36
 
38
37
  Requirements
@@ -22,5 +22,4 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec", ">= 2.6"
23
23
  s.add_development_dependency "rake"
24
24
  s.add_runtime_dependency "rchardet19"
25
- #s.add_runtime_dependency "activesupport"
26
25
  end
@@ -6,13 +6,9 @@ require 'rchardet19'
6
6
  module Enco
7
7
  # @param [String] string
8
8
  # @param [Hash] options
9
- # @option options [Boolean] :ignore_frozen
10
- def self.to_utf8 string, options = {}
9
+ def self.to_utf8(string, options = {})
11
10
  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
11
+ string = string.dup
16
12
 
17
13
  cd = ::CharDet.detect(string, :silent => true)
18
14
 
@@ -1,6 +1,7 @@
1
1
  require "enco"
2
+
2
3
  class String
3
- def to_utf8 *args
4
+ def to_utf8(*args)
4
5
  Enco.to_utf8 self, *args
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module Enco
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -3,12 +3,24 @@ require "spec_helper"
3
3
 
4
4
  # TODO add more Test cases
5
5
  describe Enco do
6
- before(:each) do
7
- @simple_string = %Q{test string\nin }
8
- @cyrillic_string = %Q{тестовая строка\nin }
6
+ it "should not touch input string" do
7
+ test_string = "test string".force_encoding "ISO-8859-15"
8
+ saved = test_string
9
+ result = Enco.to_utf8 test_string
10
+
11
+ test_string.encoding.to_s.should == "ISO-8859-15"
12
+ result.encoding.to_s.should == "UTF-8"
13
+
14
+ test_string.should === saved
9
15
  end
16
+
10
17
  describe "#to_utf8" do
11
18
  describe "argument is" do
19
+ before(:each) do
20
+ @simple_string = %Q{test string\nin }
21
+ @cyrillic_string = %Q{тестовая строка\nin }
22
+ end
23
+
12
24
  context "a string in" do
13
25
  specify "UTF-8 encoding" do
14
26
  result = Enco.to_utf8(string_in 'UTF-8')
@@ -44,26 +56,13 @@ describe Enco do
44
56
  context "a frozen string" do
45
57
  before(:each) do
46
58
  @test_string = "test string".force_encoding "ISO-8859-15"
59
+ @test_string.freeze
47
60
  end
48
61
 
49
62
  it "should perform conversion" do
50
- result = Enco.to_utf8 @test_string.freeze
63
+ result = Enco.to_utf8 @test_string
51
64
  result.encoding.to_s.should == "UTF-8"
52
65
  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
66
  end
68
67
 
69
68
  context "not a string" do
@@ -80,7 +79,6 @@ describe Enco do
80
79
  end
81
80
  end
82
81
  end
83
-
84
82
  end
85
83
  end
86
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
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: 2011-12-04 00:00:00.000000000 Z
12
+ date: 2012-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &16372380 !ruby/object:Gem::Requirement
16
+ requirement: &6560080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *16372380
24
+ version_requirements: *6560080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &16371400 !ruby/object:Gem::Requirement
27
+ requirement: &6559580 !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: *16371400
35
+ version_requirements: *6559580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rchardet19
38
- requirement: &16370800 !ruby/object:Gem::Requirement
38
+ requirement: &6583380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *16370800
46
+ version_requirements: *6583380
47
47
  description: Enco will convert any string to utf-8.
48
48
  email:
49
49
  - alexander.n.paramonov@gmail.com
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project: enco
96
- rubygems_version: 1.8.12
96
+ rubygems_version: 1.8.13
97
97
  signing_key:
98
98
  specification_version: 3
99
99
  summary: Nice utf8 converter