archive-pecan 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +12 -0
- data/lib/archive/pecan/attribute.rb +59 -0
- data/lib/archive/pecan/blob.rb +40 -0
- data/lib/archive/pecan/version.rb +8 -0
- data/lib/archive/pecan.rb +93 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f09798c77e866d10826707615d7bdabebe7395859f6c3aee7ada5a897519822e
|
4
|
+
data.tar.gz: cf2a1e6559f64cee7d9f63238d11a3e646ddfbb1f31f06c1c55f9e26df162237
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48ec8905d5549badd1f450ff114002671f38cd771e281068a27d3c6f48b2c8a09932c36b327185831d1762e6de045239d1edb2d2ce773f9e22dd69a958f852ad
|
7
|
+
data.tar.gz: 28595f022e69c4dcf51fd27cca1169e749959976b52c1ebd22a8f595d84c610c7566f0b3b0b8ee6c6f9e9564a774c774384b7d936d4459d81a0287989cc71ade
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Nathan Campos
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Pecan Gem
|
2
|
+
|
3
|
+
A Ruby gem for dealing with [Pecan🥜](https://github.com/nathanpc/pecan)
|
4
|
+
archives, which are basically files that define electronic components in your
|
5
|
+
parts bins, allowing us to have a virtual representation that is browseable of
|
6
|
+
our components in our parts bins.
|
7
|
+
|
8
|
+
|
9
|
+
## License
|
10
|
+
|
11
|
+
This project is licensed under the **MIT License**.
|
12
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Archive
|
5
|
+
class Pecan
|
6
|
+
# Abstract representation of a component attribute as a key-value pair.
|
7
|
+
#
|
8
|
+
# @author Nathan Campos <nathan@innoveworkshop.com>
|
9
|
+
class Attribute
|
10
|
+
# @return [String] Descriptive name of the attribute.
|
11
|
+
attr_accessor :name
|
12
|
+
|
13
|
+
# @return [String] Value of the attribute.
|
14
|
+
attr_accessor :value
|
15
|
+
|
16
|
+
# Initializes a component attribute.
|
17
|
+
#
|
18
|
+
# @param name [String] Descriptive name of the attribute.
|
19
|
+
# @param value [String] Value of the specified attribute.
|
20
|
+
def initialize(name = nil, value = nil)
|
21
|
+
@name = name
|
22
|
+
@value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
# Initializes a component attribute from an attribute file line.
|
26
|
+
#
|
27
|
+
# @param line [String] Attribute file line.
|
28
|
+
#
|
29
|
+
# @return [Attribute] Parsed attribute object from line.
|
30
|
+
def self.from_line(line)
|
31
|
+
attr = new
|
32
|
+
|
33
|
+
# Make sure we have a valid line.
|
34
|
+
line = line.strip
|
35
|
+
return nil if line.empty?
|
36
|
+
|
37
|
+
# Parse line and populate the object.
|
38
|
+
str = line.split("\t", 2)
|
39
|
+
attr.name = str[0]
|
40
|
+
attr.value = str[1]
|
41
|
+
|
42
|
+
attr
|
43
|
+
end
|
44
|
+
|
45
|
+
# String representation of this object just as it is represented in an
|
46
|
+
# attribute file.
|
47
|
+
#
|
48
|
+
# @return [String] Object as represented in an attribute file.
|
49
|
+
def to_s
|
50
|
+
"#{@name}\t#{value}\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
# @see to_s
|
54
|
+
def to_str
|
55
|
+
to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module Archive
|
7
|
+
class Pecan
|
8
|
+
# Abstract representation of a binary blob in an component archive.
|
9
|
+
#
|
10
|
+
# @author Nathan Campos <nathan@innoveworkshop.com>
|
11
|
+
class Blob
|
12
|
+
# @return [String] MIME type of the data contained in the blob.
|
13
|
+
attr_accessor :mime_type
|
14
|
+
|
15
|
+
# @return [#read] Blob of binary data.
|
16
|
+
attr_accessor :blob
|
17
|
+
|
18
|
+
# Initializes the blob object with data.
|
19
|
+
#
|
20
|
+
# @param mime_type [String] MIME type of the binary blob.
|
21
|
+
# @param blob [#read] Blob of binary data.
|
22
|
+
def initialize(mime_type, blob)
|
23
|
+
@mime_type = mime_type
|
24
|
+
@blob = blob
|
25
|
+
end
|
26
|
+
|
27
|
+
# String representation of the binary blob.
|
28
|
+
#
|
29
|
+
# @return [String] Base64-encoded URI string of the binary data.
|
30
|
+
def to_s
|
31
|
+
"data:#{@mime_type};charset=utf-8;base64,#{Base64.encode64(@blob)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
# @see to_s
|
35
|
+
def to_str
|
36
|
+
to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
require 'minitar'
|
6
|
+
|
7
|
+
require 'archive/pecan/attribute'
|
8
|
+
require 'archive/pecan/blob'
|
9
|
+
|
10
|
+
module Archive
|
11
|
+
# Deals with virtual electronic component files known as Pecan component
|
12
|
+
# archives.
|
13
|
+
#
|
14
|
+
# @author Nathan Campos <nathan@innoveworkshop.com>
|
15
|
+
class Pecan
|
16
|
+
MANIFEST_FILE = 'manifest.tsv'
|
17
|
+
PARAM_FILE = 'parameters.tsv'
|
18
|
+
IMAGE_FILE = 'image.bmp'
|
19
|
+
DATASHEET_FILE = 'datasheet.pdf'
|
20
|
+
|
21
|
+
# @return [Array<Attribute>] Manifest attributes.
|
22
|
+
attr_accessor :attribs
|
23
|
+
|
24
|
+
# @return [Array<Attribute>] Parameter attributes.
|
25
|
+
attr_accessor :params
|
26
|
+
|
27
|
+
# @return [Image] Component image file blob.
|
28
|
+
attr_accessor :image
|
29
|
+
|
30
|
+
# @return [Blob] Binary blob of the PDF datasheet.
|
31
|
+
attr_accessor :datasheet
|
32
|
+
|
33
|
+
# Initializes a brand new, empty, component archive object.
|
34
|
+
def initialize
|
35
|
+
@attribs = []
|
36
|
+
@params = []
|
37
|
+
@image = nil
|
38
|
+
@datasheet = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# Reads an component archive and returns an populated object that
|
42
|
+
# represents it.
|
43
|
+
#
|
44
|
+
# @param path [String] Path to the component archive to be read.
|
45
|
+
#
|
46
|
+
# @return [Archive] Object representation of the component archive.
|
47
|
+
def self.read_archive(path)
|
48
|
+
archive = new
|
49
|
+
|
50
|
+
# Open the TAR archive.
|
51
|
+
Minitar::Input.open(File.open(path, 'rb')) do |tar|
|
52
|
+
# Go through entries inside the tar file.
|
53
|
+
tar.each do |entry|
|
54
|
+
# Parse each file in its own way.
|
55
|
+
case entry.full_name
|
56
|
+
when MANIFEST_FILE
|
57
|
+
# Manifest attributes file.
|
58
|
+
StringIO.new(entry.read).each_line do |line|
|
59
|
+
attr = Attribute.from_line(line)
|
60
|
+
archive.attribs << attr unless attr.nil?
|
61
|
+
end
|
62
|
+
when PARAM_FILE
|
63
|
+
# Parameters attributes file.
|
64
|
+
StringIO.new(entry.read).each_line do |line|
|
65
|
+
attr = Attribute.from_line(line)
|
66
|
+
archive.params << attr unless attr.nil?
|
67
|
+
end
|
68
|
+
when IMAGE_FILE
|
69
|
+
# Component image file.
|
70
|
+
archive.image = Blob.new('image/bmp', entry.read)
|
71
|
+
when DATASHEET_FILE
|
72
|
+
# Component datasheet file.
|
73
|
+
archive.datasheet = Blob.new('application/pdf', entry.read)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
archive
|
79
|
+
end
|
80
|
+
|
81
|
+
# Dumps the contents of the object in a human-readable format.
|
82
|
+
def dump_contents
|
83
|
+
puts "Manifest: [#{@attribs.length}]"
|
84
|
+
@attribs.each { |attr| puts " '#{attr.name}' = '#{attr.value}'" }
|
85
|
+
|
86
|
+
puts "Parameters: [#{@params.length}]"
|
87
|
+
@params.each { |attr| puts " '#{attr.name}' = '#{attr.value}'" }
|
88
|
+
|
89
|
+
puts 'Has image' unless @image.nil?
|
90
|
+
puts 'Has datasheet' unless @datasheet.nil?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: archive-pecan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Campos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.1
|
27
|
+
description: |
|
28
|
+
Deal with virtual electronic component files known as Pecan component
|
29
|
+
archives.
|
30
|
+
email: nathan@innoveworkshop.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
- LICENSE
|
36
|
+
files:
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- lib/archive/pecan.rb
|
40
|
+
- lib/archive/pecan/attribute.rb
|
41
|
+
- lib/archive/pecan/blob.rb
|
42
|
+
- lib/archive/pecan/version.rb
|
43
|
+
homepage: https://github.com/nathanpc/pecan.rb
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
bug_tracker_uri: https://github.com/nathanpc/pecan.rb/issues
|
48
|
+
documentation_uri: https://www.rubydoc.info/gems/archive-pecan
|
49
|
+
homepage_uri: https://github.com/nathanpc/pecan.rb
|
50
|
+
source_code_uri: https://github.com/nathanpc/pecan.rb
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- "--title"
|
54
|
+
- Pecan - Virtual Electronic Component Archives
|
55
|
+
- "--main"
|
56
|
+
- README.md
|
57
|
+
- "--line-numbers"
|
58
|
+
- "--inline-source"
|
59
|
+
- "--quiet"
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.7.0
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.2.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Virtual electronic component archives
|
77
|
+
test_files: []
|