Class: Fingerprint::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/fingerprint/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode, path, metadata = {}) ⇒ Record

Returns a new instance of Record.



36
37
38
39
40
41
42
# File 'lib/fingerprint/record.rb', line 36

def initialize(mode, path,  = {})
	@mode = mode
	@path = path

	@metadata = 
	@keys = .keys.grep(/^key\./)
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



47
48
49
# File 'lib/fingerprint/record.rb', line 47

def keys
  @keys
end

#metadataObject (readonly)

Returns the value of attribute metadata.



46
47
48
# File 'lib/fingerprint/record.rb', line 46

def 
  @metadata
end

#modeObject (readonly)

Returns the value of attribute mode.



44
45
46
# File 'lib/fingerprint/record.rb', line 44

def mode
  @mode
end

#pathObject (readonly)

Returns the value of attribute path.



45
46
47
# File 'lib/fingerprint/record.rb', line 45

def path
  @path
end

Instance Method Details

#[](key) ⇒ Object



49
50
51
# File 'lib/fingerprint/record.rb', line 49

def [](key)
	@metadata[key]
end

#diff(other) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fingerprint/record.rb', line 53

def diff(other)
	changes = []

	all_keys = Set.new
	all_keys += @metadata.keys + other..keys
	# all_keys -= @keys + other.keys

	all_keys.each do |key|
		changes << key if @metadata[key].to_s != other.[key].to_s
	end

	return changes
end

#optionsObject



67
68
69
70
71
72
73
74
# File 'lib/fingerprint/record.rb', line 67

def options
	options = {}
	
	options[:extended] = true if @metadata['options.extended'] == 'true'
	options[:checksums] = @metadata['options.checksums'].split(/[\s,]+/) if @metadata['options.checksums']
	
	return options
end

#write(output) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/fingerprint/record.rb', line 76

def write(output)
	output.puts "#{MODES[@mode]} #{@path}"
	
	return if @mode == :excluded
	
	@metadata.keys.sort.each do |key|
		output.puts "\t#{key} #{@metadata[key]}"
	end
end