Class: Checkm::Entry
- Inherits:
-
Object
show all
- Defined in:
- lib/checkm/entry.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source, options = {}) ⇒ Entry
Returns a new instance of Entry.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/checkm/entry.rb', line 25
def initialize source, options = {}
@fields = options[:fields] || Manifest::BASE_FIELDS
@path = options[:path]
@path ||= Dir.pwd
@values = case source
when Hash
tmp = {}
source.each { |k, v| tmp[k.to_s.downcase.to_sym] = v }
@fields.map { |k| source[k.to_s.downcase.to_sym] }
when Array
source
when String
source.split("|").map { |x| x.strip }
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
54
55
56
|
# File 'lib/checkm/entry.rb', line 54
def method_missing(sym, *args, &block)
self[@fields.map { |x| x.downcase }.index(sym.to_s.downcase) || Manifest::BASE_FIELDS.map { |x| x.downcase }.index(sym.to_s.downcase)]
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
23
24
25
|
# File 'lib/checkm/entry.rb', line 23
def fields
@fields
end
|
#values ⇒ Object
Returns the value of attribute values.
22
23
24
|
# File 'lib/checkm/entry.rb', line 22
def values
@values
end
|
Class Method Details
.create(file_or_path, args = {}) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/checkm/entry.rb', line 4
def self.create file_or_path, args = {}
return file_or_path if file_or_path.is_a? Entry
options = args.delete(:options) || {}
path = options[:path] || Dir.pwd
file = file_or_path if file.is_a? File
file ||= File.open(File.expand_path(file_or_path, path))
args[:sourcefileorurl] = File.expand_path(file.path).gsub(path + "/", '') if file.respond_to? :path
args[:alg] ||= 'md5'
args[:digest] ||= Checkm.checksum(file, args[:alg])
args[:length] ||= File.size(file.path)
args[:modtime] ||= file.mtime.utc.xmlschema
Checkm::Entry.new(args, options)
end
|
Instance Method Details
#[](idx) ⇒ Object
42
43
44
|
# File 'lib/checkm/entry.rb', line 42
def [] idx
values[idx] rescue nil
end
|
#[]=(idx, value) ⇒ Object
46
47
48
|
# File 'lib/checkm/entry.rb', line 46
def []= idx, value
values[idx] = value rescue nil
end
|
#to_s ⇒ Object
50
51
52
|
# File 'lib/checkm/entry.rb', line 50
def to_s
values.join(" | ")
end
|
#valid? ⇒ Boolean
58
59
60
|
# File 'lib/checkm/entry.rb', line 58
def valid?
return File.exists?(source) && valid_checksum? end
|