Class: Archive::Pecan
- Inherits:
-
Object
- Object
- Archive::Pecan
- Defined in:
- lib/archive/pecan.rb,
lib/archive/pecan/blob.rb,
lib/archive/pecan/version.rb,
lib/archive/pecan/attribute.rb
Overview
Deals with virtual electronic component files known as Pecan component archives.
Defined Under Namespace
Constant Summary collapse
- MANIFEST_FILE =
'manifest.tsv'- PARAM_FILE =
'parameters.tsv'- IMAGE_FILE =
'image.bmp'- DATASHEET_FILE =
'datasheet.pdf'- VERSION =
'0.1.0'
Instance Attribute Summary collapse
-
#attribs ⇒ Array<Attribute>
Manifest attributes.
-
#datasheet ⇒ Blob
Binary blob of the PDF datasheet.
-
#image ⇒ Image
Component image file blob.
-
#params ⇒ Array<Attribute>
Parameter attributes.
Class Method Summary collapse
-
.read_archive(path) ⇒ Archive
Reads an component archive and returns an populated object that represents it.
Instance Method Summary collapse
-
#dump_contents ⇒ Object
Dumps the contents of the object in a human-readable format.
-
#initialize ⇒ Pecan
constructor
Initializes a brand new, empty, component archive object.
Constructor Details
#initialize ⇒ Pecan
Initializes a brand new, empty, component archive object.
34 35 36 37 38 39 |
# File 'lib/archive/pecan.rb', line 34 def initialize @attribs = [] @params = [] @image = nil @datasheet = nil end |
Instance Attribute Details
#attribs ⇒ Array<Attribute>
Returns Manifest attributes.
22 23 24 |
# File 'lib/archive/pecan.rb', line 22 def attribs @attribs end |
#datasheet ⇒ Blob
Returns Binary blob of the PDF datasheet.
31 32 33 |
# File 'lib/archive/pecan.rb', line 31 def datasheet @datasheet end |
#image ⇒ Image
Returns Component image file blob.
28 29 30 |
# File 'lib/archive/pecan.rb', line 28 def image @image end |
#params ⇒ Array<Attribute>
Returns Parameter attributes.
25 26 27 |
# File 'lib/archive/pecan.rb', line 25 def params @params end |
Class Method Details
.read_archive(path) ⇒ Archive
Reads an component archive and returns an populated object that represents it.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/archive/pecan.rb', line 47 def self.read_archive(path) archive = new # Open the TAR archive. Minitar::Input.open(File.open(path, 'rb')) do |tar| # Go through entries inside the tar file. tar.each do |entry| # Parse each file in its own way. case entry.full_name when MANIFEST_FILE # Manifest attributes file. StringIO.new(entry.read).each_line do |line| attr = Attribute.from_line(line) archive.attribs << attr unless attr.nil? end when PARAM_FILE # Parameters attributes file. StringIO.new(entry.read).each_line do |line| attr = Attribute.from_line(line) archive.params << attr unless attr.nil? end when IMAGE_FILE # Component image file. archive.image = Blob.new('image/bmp', entry.read) when DATASHEET_FILE # Component datasheet file. archive.datasheet = Blob.new('application/pdf', entry.read) end end end archive end |
Instance Method Details
#dump_contents ⇒ Object
Dumps the contents of the object in a human-readable format.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/archive/pecan.rb', line 82 def dump_contents puts "Manifest: [#{@attribs.length}]" @attribs.each { |attr| puts " '#{attr.name}' = '#{attr.value}'" } puts "Parameters: [#{@params.length}]" @params.each { |attr| puts " '#{attr.name}' = '#{attr.value}'" } puts 'Has image' unless @image.nil? puts 'Has datasheet' unless @datasheet.nil? end |