file_classify 0.0.1 → 0.0.2

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: 2145249459482451c944d8510de554d92175533b
4
- data.tar.gz: 1cad6de9ade4bcdca69d201063657e51c85d1db3
3
+ metadata.gz: 2602de0b80f2ba410f75037c3f1dc61dc0f2d929
4
+ data.tar.gz: b3cc1c0ea8bc32e78ec0475ad48f91411ef7868a
5
5
  SHA512:
6
- metadata.gz: 6bded4aabd3bdd4fd4f2c83f3209a7d304b88898b58e670a82993683e40146d9dd5760a0c8dca8745dac301469324d298d12c42be6f655e7ce46510ec40439e9
7
- data.tar.gz: 19c94ceccd39958acbad53dc4a2b1a8327f1c5e09bfd5b73a456d14b7c26f46290177b85457acb9ee18fe965159dad3664698d7443317f084b4cbe767d070c57
6
+ metadata.gz: 2ff5f2546327bfb490e2995d70e1162bef50a4129c5b918a4fe736c2a87d328da40c6cb778e50c5192912aa4541516a63c89cd3177e73e0852d65c161a3444dc
7
+ data.tar.gz: 04a5c55ea60d4a9a02630ec52e4df4634b49a7970cd45be257739c39b815edd76e0cd72733378eb6f9a7db38727e414098fbb484707e9a21f2f67ff129ae0394
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Binary and ASCII classification for files
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/file_classify.png)](http://badge.fury.io/rb/file_classify)
6
+ [![Build Status](https://travis-ci.org/rcaught/file_classify.png?branch=master)](https://travis-ci.org/rcaught/file_classify)
7
+ [![Dependency Status](https://gemnasium.com/rcaught/file_classify.png)](https://gemnasium.com/rcaught/file_classify)
8
+ [![Coverage Status](https://coveralls.io/repos/rcaught/file_classify/badge.png)](https://coveralls.io/r/rcaught/file_classify)
9
+ [![Code Climate](https://codeclimate.com/github/rcaught/file_classify.png)](https://codeclimate.com/github/rcaught/file_classify)
10
+
5
11
  ## Installation
6
12
 
7
13
  Add this line to your application's Gemfile:
@@ -18,7 +24,30 @@ Or install it yourself as:
18
24
 
19
25
  ## Usage
20
26
 
21
- TODO: Write usage instructions here
27
+ ```ruby
28
+ require 'file_classify'
29
+
30
+ classifier = FileClassify.new(path: 'spec/resources/binary.jpg')
31
+ => #<FileClassify:0x007fbf04c31098 @contents=nil, @path="spec/resources/binary.jpg">
32
+ classifier.binary?
33
+ => true
34
+ classifier.ascii?
35
+ => false
36
+ classifier.classify
37
+ => "binary"
38
+
39
+
40
+ # Or perhaps you have file contents?
41
+
42
+ classifier = FileClassify.new(contents: 'And miles to go before I sleep.')
43
+ => #<FileClassify:0x007fbf04cd0ff8 @contents="And miles to go before I sleep.", @path=nil>
44
+ classifier.binary?
45
+ => false
46
+ classifier.ascii?
47
+ => true
48
+ classifier.classify
49
+ => "ascii"
50
+ ```
22
51
 
23
52
  ## Contributing
24
53
 
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
data/lib/file_classify.rb CHANGED
@@ -17,8 +17,8 @@ class FileClassify
17
17
  file_path = self.path
18
18
 
19
19
  if self.contents
20
- temp = Tempfile.new('block_size_check')
21
- temp.write(self.contents)
20
+ temp = Tempfile.new('block_size_check', encoding: 'utf-8')
21
+ temp.write(self.contents.force_encoding('utf-8'))
22
22
  temp.close
23
23
 
24
24
  file_path = temp.path
@@ -1,3 +1,3 @@
1
1
  class FileClassify
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -9,6 +9,10 @@ describe FileClassify do
9
9
  FileClassify.new(contents: File.read(BINARY_FILE))
10
10
  end
11
11
 
12
+ let :binary_ascii_8bit_contents_subject do
13
+ FileClassify.new(contents: File.read(BINARY_FILE).force_encoding('ascii-8bit'))
14
+ end
15
+
12
16
  let :binary_path_subject do
13
17
  FileClassify.new(path: BINARY_FILE)
14
18
  end
@@ -59,6 +63,10 @@ describe FileClassify do
59
63
  ascii_contents_subject.binary?.should be_false
60
64
  ascii_path_subject.binary?.should be_false
61
65
  end
66
+
67
+ it 'handles ascii-8bit encoded content strings' do
68
+ binary_ascii_8bit_contents_subject.binary?.should be_true
69
+ end
62
70
  end
63
71
 
64
72
  context '#ascii?' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_classify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Caught
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler