Class: Magika::FileType

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#scoreObject (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

#inspectObject



153
154
155
# File 'lib/magika.rb', line 153

def inspect
  "#<#{self.class} label=#{label} score=#{score} #{mime_type} #{description.dump} (#{group})>"
end

#labelObject



138
139
140
141
# File 'lib/magika.rb', line 138

def label
  content_type
  @overwritten || @inferred_label
end

#text?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/magika.rb', line 149

def text?
  content_type[:is_text]
end