Class: Fingerprint::Record
- Inherits:
-
Object
- Object
- Fingerprint::Record
- Defined in:
- lib/fingerprint/record.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #diff(other) ⇒ Object
-
#initialize(mode, path, metadata = {}) ⇒ Record
constructor
A new instance of Record.
- #options ⇒ Object
- #write(output) ⇒ Object
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
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
47 48 49 |
# File 'lib/fingerprint/record.rb', line 47 def keys @keys end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
46 47 48 |
# File 'lib/fingerprint/record.rb', line 46 def @metadata end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
44 45 46 |
# File 'lib/fingerprint/record.rb', line 44 def mode @mode end |
#path ⇒ Object (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 |
#options ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/fingerprint/record.rb', line 67 def = {} [:extended] = true if @metadata['options.extended'] == 'true' [:checksums] = @metadata['options.checksums'].split(/[\s,]+/) if @metadata['options.checksums'] return 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 |