file_type_detector_sfedu 0.2.1 → 0.2.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
  SHA256:
3
- metadata.gz: 9449915d78b7866c453a5a8cb813839d83f3f96e39beac2f2c15dd5f94df712b
4
- data.tar.gz: a52208251fa8436adb24a6b15b051cc6fa730de720c05774e83d14beafa36602
3
+ metadata.gz: 58a8d37d3931c29954f7870c6125905261def1d31d71bcd4ebcba1e7499b4a61
4
+ data.tar.gz: f9201f1e4bfec70f6a63dce6fa652cbac8e215f82078e47f93daff2b4bc661cd
5
5
  SHA512:
6
- metadata.gz: 3c90836cd61fa5af87721f74abdc53687fa5cc35a3bbb9587de1eecbf8be00f922d80d4e9b128c79318248fb3e472554cd4f5257f65986169e8e73feb0aebb2e
7
- data.tar.gz: 00abb630169031a53cc78834f3f711d4235ae1fb3c3b698e85e9f743b956fda39af44fafd49fb847a23321c21bac4a7fb902a26f667593955e5b0c60881ba92f
6
+ metadata.gz: 1251c06470e171d5fda3eff3a1514253e80305a5cbe8d3e24c190f522e4f445dcd9de2ddbd8f75668737e5c108173bfafaa39b3f4a9daffcaaf2b438acf7e4bf
7
+ data.tar.gz: 7aed639f2d0f518aa09dbdb711b79695551f5f47e9336df265d8344294d8379ee66ad7b2e3141d342211550803f05dfe4f49f1aa0e8da5982a22e611937a6b1b
data/CHANGELOG.md CHANGED
@@ -21,4 +21,9 @@
21
21
  ## [0.2.1] - 2024-04-6
22
22
 
23
23
  - Added documentation to all functions
24
+ - Other minor improvements
25
+
26
+ ## [0.2.2] - 2024-04-08
27
+
28
+ - Bug fixed
24
29
  - Other minor improvements
data/README.md CHANGED
@@ -28,13 +28,21 @@ puts FileTypeDetector.check("path/to/your/file.pdf") # if it's truly pdf, value
28
28
 
29
29
  You can also use a specific detector:
30
30
  ```ruby
31
- puts FileTypeDetector.pdf_check("path/to/your/real_pdf.pdf") # true
32
- puts FileTypeDetector.pdf_check("path/to/your/fake_pdf.pdf") # false
31
+ puts FileTypeDetector.pdf_check("path/to/your/real_pdf.pdf") # true
32
+ puts FileTypeDetector.pdf_check("path/to/your/fake_pdf.pdf") # false
33
33
 
34
34
  puts FileTypeDetector.docx_check("path/to/your/real_docx.docx") # true
35
35
  puts FileTypeDetector.docx_check("path/to/your/fake_docx.docx") # false
36
36
  ```
37
37
 
38
+ You can also run all the detectors on the file to determine its type using the `identify` method:
39
+ ```ruby
40
+ puts FileTypeDetector.identify("path/to/your/real_pdf.pdf") # "pdf"
41
+ puts FileTypeDetector.identify("path/to/your/real_xml.pdf") # "xml"
42
+ puts FileTypeDetector.identify("path/to/your/real_docx.docx") # docx
43
+ puts FileTypeDetector.identify("path/to/your/real_jpeg.png") # jpeg
44
+ puts FileTypeDetector.identify("path/to/your/unknown.png") # nil
45
+ ```
38
46
  ## Supported File Types
39
47
  The gem provides support for detecting the following file types:
40
48
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FileTypeDetector
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -27,7 +27,7 @@ module FileTypeDetector
27
27
  def self.identify(file_path)
28
28
  return unless error_handling(file_path)
29
29
 
30
- FILE_CHECKS.find { |fn| fn.call(file_path)}.name.to_s.split("_")[0][1..]
30
+ FILE_CHECKS.find { |fn| fn.call(file_path)}.name.to_s.split("_")[0]
31
31
  end
32
32
 
33
33
  # =============================================
@@ -72,7 +72,7 @@ module FileTypeDetector
72
72
  return unless error_handling(file_path)
73
73
 
74
74
  first_bytes = File.open(file_path, "rb") { |file| file.read(16) }
75
- first_bytes.start_with?("\x89PNG\r\n\x1A\n".b)
75
+ first_bytes&.start_with?("\x89PNG\r\n\x1A\n".b)
76
76
  end
77
77
 
78
78
  # Checks if the file has a GIF format.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_type_detector_sfedu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garik Mnacakanyan
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2024-04-06 00:00:00.000000000 Z
14
+ date: 2024-04-08 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: FileTypeDetector is a Ruby gem that provides functionality for determining
17
17
  the type of a file based on its extension or content.