Class: Fsinv::Inventory

Inherits:
Object
  • Object
show all
Includes:
Fsinv
Defined in:
lib/fsinv/inventory.rb

Constant Summary

Constants included from Fsinv

BYTES_IN_GB, BYTES_IN_GiB, BYTES_IN_KB, BYTES_IN_KiB, BYTES_IN_MB, BYTES_IN_MiB, BYTES_IN_TB, BYTES_IN_TiB, IGNORE_FILES, PSEUDO_FILES, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fsinv

filestructure_to_db, filestructure_to_xml, inventory_to_json, inventory_to_xml, inventory_to_yaml, parse, pretty_IEC_bytes, pretty_SI_bytes, sanitize_string

Constructor Details

#initialize(file_structure) ⇒ Inventory

Returns a new instance of Inventory.



12
13
14
15
16
17
18
19
# File 'lib/fsinv/inventory.rb', line 12

def initialize(file_structure)
  @file_structure = file_structure
  @timestamp  = Time.now
  @magic_tab  = Fsinv.magic_tab
  @mime_tab   = Fsinv.mime_tab
  @osx_tab    = Fsinv.osx_tab
  @fshugo_tab = Fsinv.fshugo_tab
end

Instance Attribute Details

#file_structureObject

Returns the value of attribute file_structure.



10
11
12
# File 'lib/fsinv/inventory.rb', line 10

def file_structure
  @file_structure
end

#fshugo_tabObject

Returns the value of attribute fshugo_tab.



10
11
12
# File 'lib/fsinv/inventory.rb', line 10

def fshugo_tab
  @fshugo_tab
end

#magic_tabObject

Returns the value of attribute magic_tab.



10
11
12
# File 'lib/fsinv/inventory.rb', line 10

def magic_tab
  @magic_tab
end

#mime_tabObject

Returns the value of attribute mime_tab.



10
11
12
# File 'lib/fsinv/inventory.rb', line 10

def mime_tab
  @mime_tab
end

#osx_tabObject

Returns the value of attribute osx_tab.



10
11
12
# File 'lib/fsinv/inventory.rb', line 10

def osx_tab
  @osx_tab
end

#timestampObject

Returns the value of attribute timestamp.



10
11
12
# File 'lib/fsinv/inventory.rb', line 10

def timestamp
  @timestamp
end

Instance Method Details

#as_json(options = { }) ⇒ Object



49
50
51
# File 'lib/fsinv/inventory.rb', line 49

def as_json(options = { })
  return to_hash
end

#item_countObject



29
30
31
32
33
34
35
# File 'lib/fsinv/inventory.rb', line 29

def item_count
  count = 0
  file_structure.each do |fs|
    count += fs.item_count
  end
  return count
end

#marshal_dumpObject



57
58
59
# File 'lib/fsinv/inventory.rb', line 57

def marshal_dump
  return to_hash
end

#marshal_load(data) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/fsinv/inventory.rb', line 61

def marshal_load(data)
  self.file_structure = data['file_structure'] if data['file_structure'].exists?
  self.timestamp = data['timestamp'] if data['timestamp'].exists?
  self.magic_tab = data['magic_tab'] if data['magic_tab'].exists?
  self.mime_tab = data['mime_tab'] if data['mime_tab'].exists?
  self.osx_tab = data['osx_tab'] if data['osx_tab'].exists?
  self.fshugo_tab = data['fshugo_tab'] if data['fshugo_tab'].exists?
end

#sizeObject



21
22
23
24
25
26
27
# File 'lib/fsinv/inventory.rb', line 21

def size
  size = 0
  file_structure.each do |fs|
    size += fs.bytes
  end
  return size
end

#to_hashObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fsinv/inventory.rb', line 37

def to_hash
  h = {
    "timestamp" => @timestamp,
    "file_structure" => @file_structure,
  }
  h["mime_tab"] = @mime_tab unless @mime_tab.empty?
  h["magic_tab"] = @magic_tab unless @magic_tab.empty?
  h["osx_tab"] = @osx_tab unless @osx_tab.empty?
  h["fshugo_tab"] = @fshugo_tab unless @fshugo_tab.empty?
  return h
end

#to_json(*a) ⇒ Object



53
54
55
# File 'lib/fsinv/inventory.rb', line 53

def to_json(*a)
  as_json.to_json(*a)
end