ocho 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ocho.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 andrea longhi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Ocho
2
+
3
+ Read a file and convert the obtained string to utf-8. Suitable for Ruby < 1.9
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ocho'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ocho
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ utf8_text = Ocho.read(some_extoteric_filename) #=> ...
23
+
24
+ Ocho.encoding(utf8_text) #=> ascii
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ require 'ocho/version'
2
+
3
+ module Ocho
4
+ autoload :Converter, 'ocho/converter'
5
+ extend self
6
+
7
+ def encoding(text)
8
+ Converter.new(text).encoding
9
+ end
10
+
11
+ def read(filename)
12
+ content = File.read(filename)
13
+ Converter.new(content).to_utf8
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ require 'iconv'
2
+ require 'rchardet'
3
+ require 'active_support/core_ext/class/attribute'
4
+
5
+ module Ocho
6
+ class Converter
7
+ class_attribute :strategy
8
+
9
+ class << self
10
+ def strategy
11
+ '//TRANSLIT//IGNORE'
12
+ end
13
+ end
14
+
15
+ attr_reader :text
16
+ attr_writer :strategy
17
+
18
+ def initialize(text)
19
+ @text = text
20
+ end
21
+
22
+ def encoding
23
+ CharDet.detect(text)['encoding']
24
+ end
25
+
26
+ def to_utf8
27
+ Iconv.conv("#{encoding}#{strategy}", 'utf-8', text)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Ocho
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ocho/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["andrea longhi"]
6
+ gem.email = ["andrea@spaghetticode.it"]
7
+ gem.description = %q{Reads a file, guesses the charset and converts to utf-8}
8
+ gem.summary = %q{Reads a file, guesses the charset and converts to utf-8}
9
+ gem.homepage = "https://github.com/spaghetticode/ocho.git"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ocho"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Ocho::VERSION
17
+
18
+ gem.add_dependency 'rake'
19
+ gem.add_dependency 'iconv'
20
+ gem.add_dependency 'rchardet'
21
+ gem.add_dependency 'activesupport'
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'guard-rspec'
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Ocho
4
+ describe Converter do
5
+ let(:converter) {Converter.new('beechwood park') }
6
+
7
+ it 'has a very permissive default strategy' do
8
+ Converter.new('').strategy.should == '//TRANSLIT//IGNORE'
9
+ end
10
+
11
+ it 'has a setter for the strategy' do
12
+ strategy = 'lucy in the sky with diamonds'
13
+ expect do
14
+ converter.strategy = strategy
15
+ end.to change(converter, :strategy).to(strategy)
16
+ end
17
+
18
+ it 'correctly detects EUC-KR charset' do
19
+ text = File.read fixture_file('EUC-KR.txt')
20
+ Converter.new(text).encoding.should == 'EUC-KR'
21
+ end
22
+
23
+ it 'correctly convert to UTF-8' do
24
+ text = File.read fixture_file('EUC-KR.txt')
25
+ Converter.new(text).to_utf8.should == "Armani; Kurf\"Yrstendamm, Berlin Germany"
26
+ end
27
+
28
+ it 'correctly save the converted version to a file' do
29
+ text = File.read fixture_file('EUC-KR.txt')
30
+ File.open fixture_file('test.txt'), 'w' do |f|
31
+ f.write Converter.new(text).to_utf8
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ Armani; KurfŸrstendamm, Berlin Germany
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ocho do
4
+ describe '::encoding' do
5
+ it 'returns the encoding of a string' do
6
+ Ocho.encoding('runaway').should == 'ascii'
7
+ end
8
+ end
9
+
10
+ describe '::read' do
11
+ it 'reads a file and converts the content to ascii' do
12
+ text = Ocho.read fixture_file('EUC-KR.txt')
13
+ Ocho.encoding(text).should == 'ascii'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'ocho'
4
+
5
+ RSpec.configure do |config|
6
+ config.color = true
7
+ end
8
+
9
+ def fixture_file(filename)
10
+ File.expand_path("../fixtures/#{filename}", __FILE__)
11
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ocho
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - andrea longhi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-11-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ requirement: *id001
25
+ prerelease: false
26
+ - !ruby/object:Gem::Dependency
27
+ name: iconv
28
+ version_requirements: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ type: :runtime
35
+ requirement: *id002
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ name: rchardet
39
+ version_requirements: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :runtime
46
+ requirement: *id003
47
+ prerelease: false
48
+ - !ruby/object:Gem::Dependency
49
+ name: activesupport
50
+ version_requirements: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :runtime
57
+ requirement: *id004
58
+ prerelease: false
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ version_requirements: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :development
68
+ requirement: *id005
69
+ prerelease: false
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-rspec
72
+ version_requirements: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ requirement: *id006
80
+ prerelease: false
81
+ description: Reads a file, guesses the charset and converts to utf-8
82
+ email:
83
+ - andrea@spaghetticode.it
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - Guardfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - lib/ocho.rb
98
+ - lib/ocho/converter.rb
99
+ - lib/ocho/version.rb
100
+ - ocho.gemspec
101
+ - spec/converter_spec.rb
102
+ - spec/fixtures/EUC-KR.txt
103
+ - spec/ocho_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/spaghetticode/ocho.git
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.24
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Reads a file, guesses the charset and converts to utf-8
138
+ test_files:
139
+ - spec/converter_spec.rb
140
+ - spec/fixtures/EUC-KR.txt
141
+ - spec/ocho_spec.rb
142
+ - spec/spec_helper.rb