Class: Dcc::Extract::File
- Inherits:
-
Object
- Object
- Dcc::Extract::File
- Defined in:
- lib/dcc/extract/file.rb
Overview
Dcc::Extract::File enumerates embedded files (dcc:byteDataType
elements) inside a parsed DCC. Each entry carries the decoded binary
payload, MIME type, file name, and the surrounding ring.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ring ⇒ Object
readonly
Returns the value of attribute ring.
Class Method Summary collapse
- .at(dcc, index) ⇒ Dcc::Extract::File?
-
.each(dcc) {|| ... } ⇒ Array<Dcc::Extract::File>
Walk a parsed DCC and yield each embedded file in document order.
- .in_ring(dcc, ring:) ⇒ Array<Dcc::Extract::File>
Instance Method Summary collapse
-
#initialize(name:, file_name:, mime_type:, data:, ring:) ⇒ File
constructor
A new instance of File.
-
#text? ⇒ Boolean
True if the embedded payload is textual (text/*).
- #to_s ⇒ Object
Constructor Details
#initialize(name:, file_name:, mime_type:, data:, ring:) ⇒ File
Returns a new instance of File.
19 20 21 22 23 24 25 |
# File 'lib/dcc/extract/file.rb', line 19 def initialize(name:, file_name:, mime_type:, data:, ring:) @name = name @file_name = file_name @mime_type = mime_type @data = data @ring = ring end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/dcc/extract/file.rb', line 12 def data @data end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
12 13 14 |
# File 'lib/dcc/extract/file.rb', line 12 def file_name @file_name end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
12 13 14 |
# File 'lib/dcc/extract/file.rb', line 12 def mime_type @mime_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/dcc/extract/file.rb', line 12 def name @name end |
#ring ⇒ Object (readonly)
Returns the value of attribute ring.
12 13 14 |
# File 'lib/dcc/extract/file.rb', line 12 def ring @ring end |
Class Method Details
.at(dcc, index) ⇒ Dcc::Extract::File?
74 75 76 |
# File 'lib/dcc/extract/file.rb', line 74 def at(dcc, index) each(dcc)[index] end |
.each(dcc) {|| ... } ⇒ Array<Dcc::Extract::File>
Walk a parsed DCC and yield each embedded file in document order. Detects cycles (recursive list) via object_id tracking so the walk terminates for self-referential subtrees.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dcc/extract/file.rb', line 43 def each(dcc, &block) list = [] visited = ::Set.new collect = lambda do |node, ring| return unless node.is_a?(::Lutaml::Model::Serializable) return if visited.include?(node.object_id) visited << node.object_id new_ring = if admin_data?(node) Ring::ADMINISTRATIVE_DATA elsif measurement_list?(node) Ring::MEASUREMENT_RESULTS else ring end list << build_file(node, new_ring) if byte_data?(node) walk_children(node, new_ring, collect) end collect.call(dcc, nil) return list unless block_given? list.each(&block) end |
.in_ring(dcc, ring:) ⇒ Array<Dcc::Extract::File>
81 82 83 |
# File 'lib/dcc/extract/file.rb', line 81 def in_ring(dcc, ring:) each(dcc).select { |f| f.ring == ring } end |
Instance Method Details
#text? ⇒ Boolean
Returns true if the embedded payload is textual (text/*).
28 29 30 |
# File 'lib/dcc/extract/file.rb', line 28 def text? mime_type.to_s.start_with?("text/") end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/dcc/extract/file.rb', line 32 def to_s "File #{file_name || '(unnamed)'} [#{ring}] (#{mime_type}, #{data.bytesize} bytes)" end |