Class: Magika::FileType
- Inherits:
-
Object
- Object
- Magika::FileType
- Defined in:
- lib/magika.rb
Constant Summary collapse
- CONTENT_TYPES_PATH =
File.join(ASSETS_DIR, "content_types_kb.min.json")
- CONTENT_TYPES =
JSON.load_file(CONTENT_TYPES_PATH, symbolize_names: true)
- MEDIUM_CONFIDENCE_THRESHOLD =
- THRESHOLDS =
Instance Attribute Summary collapse
-
#score ⇒ Object
readonly
Returns the value of attribute score.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(label, score) ⇒ FileType
constructor
A new instance of FileType.
- #inspect ⇒ Object
- #label ⇒ Object
- #text? ⇒ Boolean
Constructor Details
#initialize(label, score) ⇒ FileType
Returns a new instance of FileType.
131 132 133 134 135 136 |
# File 'lib/magika.rb', line 131 def initialize(label, score) @inferred_label = label @score = score @overwritten = nil @content_type = nil end |
Instance Attribute Details
#score ⇒ Object (readonly)
Returns the value of attribute score.
121 122 123 |
# File 'lib/magika.rb', line 121 def score @score end |
Class Method Details
.from_inference(inference) ⇒ Object
124 125 126 127 128 |
# File 'lib/magika.rb', line 124 def from_inference(inference) index = inference.argmax score = inference[index] FileType.new(TARGET_LABELS_SPACE[index], score) end |
Instance Method Details
#inspect ⇒ Object
153 154 155 |
# File 'lib/magika.rb', line 153 def inspect "#<#{self.class} label=#{label} score=#{score} #{mime_type} #{description.dump} (#{group})>" end |
#label ⇒ Object
138 139 140 141 |
# File 'lib/magika.rb', line 138 def label content_type @overwritten || @inferred_label end |
#text? ⇒ Boolean
149 150 151 |
# File 'lib/magika.rb', line 149 def text? content_type[:is_text] end |