uniconvert 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eac236a3c9e9a790568c57d8a92a93d89cdefe12
4
- data.tar.gz: 79758160373a14fca079793295884d85246c4748
3
+ metadata.gz: 1e630d67664e5e4a94c1240d1a662c822172552b
4
+ data.tar.gz: 44da5d234bec3a2f42f0794e331bcaad81bf0a36
5
5
  SHA512:
6
- metadata.gz: cebc6ab80bd71efee9f16bb9e6b1d4513a110e097b90844dfa52255b68b8b2f8366d06d5f9df6fcb06e19a114f8b27a63f0c913f543bdf8dffe47a3e63f2cfae
7
- data.tar.gz: c2f40c84ce1ec9882ef1ef54df7297f4a6d50ed3e63b02255d103944448e4e22a23d25434fe4b9ddd7493dc75a4498aea15791f05bdc0ade747e7342840a1f69
6
+ metadata.gz: b518094b45b8e7bbeab5180177c755c3c8682416734549dc499db453430f6b4b8b067441415ffaa53e4544a7fe42a4552584ae870add4fbb694241198a0bde39
7
+ data.tar.gz: 88d81e153dc6dce95554a2436ddb80fe84036eb1b2cd63c72b4960603d6964e54f603d5d0dc9ca454e735ae66ec446079b2742e180dfe0a790b5edd898c87161
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.converted
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Uniconvert
2
2
 
3
- Various conversions for non-Latin characters. So far the only method is `to_html`, to convert things like "Â" to "Â", but more will be added as required.
3
+ Various conversions for non-Latin characters. So far the only method is `to_html`, to convert things like "Â" to "& Acirc;" (but without the space), but more will be added as required.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ Using the binary:
24
+
25
+ ```shell
26
+ $ uniconvert /path/to/file.txt
27
+ ```
28
+
29
+ In Ruby
30
+
31
+ ```ruby
32
+ text = Uniconvert.to(:HTML, 'Maître Corbeau, sur un arbre perché')
33
+
34
+ some_field.text(text)
35
+ ```
24
36
 
25
37
  ## Development
26
38
 
data/exe/uniconvert CHANGED
@@ -3,8 +3,15 @@
3
3
  require 'rubygems'
4
4
  require 'htmlentities'
5
5
  require 'unicode'
6
+ require 'notifaction'
7
+ require 'iconv'
8
+
9
+ Dir['lib/uniconvert/converters/*'].each do |f|
10
+ require_relative "../#{f}"
11
+ end
6
12
 
7
13
  require_relative "../lib/uniconvert.rb"
8
14
 
9
15
  # convert the file to HTML-safe characters
10
- Uniconvert.to_html(ARGV[0])
16
+ # Uniconvert.to(:HTML, ARGV[0])
17
+ Uniconvert.to(:ASCII, ARGV[0])
@@ -0,0 +1,28 @@
1
+ module Uniconvert
2
+ class HTML
3
+ attr_accessor :encoder
4
+
5
+ def initialize(should_create_file = true)
6
+ @create_file = should_create_file
7
+ @encoder = HTMLEntities.new
8
+ end
9
+
10
+ def convert(file)
11
+ file_contents = File.read(file)
12
+ converted = @encoder.encode(file_contents, :named)
13
+
14
+ if @create_file
15
+ translated_file_name = file + '.converted'
16
+
17
+ File.open(translated_file_name, 'w+') do |f|
18
+ f.write converted
19
+ end
20
+
21
+ `$EDITOR #{translated_file_name}`
22
+ end
23
+
24
+ converted.nil?
25
+ end
26
+
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Uniconvert
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/uniconvert.rb CHANGED
@@ -1,18 +1,16 @@
1
1
  module Uniconvert
2
- def self.to_html(file, create_file = true)
3
- coder = HTMLEntities.new
4
- non_latin_strings = File.read(file)
5
- translated_file_name = file + '.converted'
6
- converted = coder.encode(non_latin_strings, :named)
7
2
 
8
- if create_file
9
- File.open(translated_file_name, 'w+') do |f|
10
- f.write converted
11
- end
12
-
13
- `$EDITOR #{translated_file_name}`
14
- end
15
-
16
- converted.nil?
3
+ #
4
+ # Convert the text in the file using one of the supported conversion handlers
5
+ #
6
+ # @converter Symbol The converter you'd like to use
7
+ # @file String Path to the input file which contains the text you'd
8
+ # like to convert
9
+ # @create_file Bool Flag to create a new file with the converted data
10
+ #
11
+ def self.to(converter, file, create_file = false)
12
+ converter_obj = Uniconvert.const_get(converter).new(create_file)
13
+ converter_obj.convert(file)
17
14
  end
15
+
18
16
  end
data/uniconvert.gemspec CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "htmlentities", "~> 4.3.4"
22
22
  spec.add_runtime_dependency "unicode"
23
+ spec.add_runtime_dependency "notifaction"
24
+ spec.add_runtime_dependency "iconv"
23
25
 
24
26
  spec.add_development_dependency "bundler", "~> 1.12"
25
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniconvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: notifaction
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: iconv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +126,7 @@ files:
98
126
  - bin/setup
99
127
  - exe/uniconvert
100
128
  - lib/uniconvert.rb
129
+ - lib/uniconvert/converters/HTML.rb
101
130
  - lib/uniconvert/version.rb
102
131
  - uniconvert.gemspec
103
132
  homepage: https://rubygems.org/aapis/unicode-lang-converter