Class: Nexpose::File

Inherits:
APIObject show all
Defined in:
lib/nexpose/asset.rb

Overview

File or directory on an asset.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from APIObject

#object_from_hash

Constructor Details

#initialize(name = nil, size = 0, directory = false, attributes = []) ⇒ File

Returns a new instance of File.



234
235
236
# File 'lib/nexpose/asset.rb', line 234

def initialize(name = nil, size = 0, directory = false, attributes = [])
  @name, @size, @directory, @attributes = name, size, directory, attributes
end

Instance Attribute Details

#attributesObject (readonly)

File attributes.



230
231
232
# File 'lib/nexpose/asset.rb', line 230

def attributes
  @attributes
end

#directoryObject (readonly)

Whether the file is a directory.



232
233
234
# File 'lib/nexpose/asset.rb', line 232

def directory
  @directory
end

#nameObject (readonly)

Name of the file.



226
227
228
# File 'lib/nexpose/asset.rb', line 226

def name
  @name
end

#sizeObject (readonly)

Size of the file.



228
229
230
# File 'lib/nexpose/asset.rb', line 228

def size
  @size
end

Instance Method Details

#<=>(other) ⇒ Object



249
250
251
252
253
254
255
256
257
# File 'lib/nexpose/asset.rb', line 249

def <=>(other)
  c = name <=> other.name
  return c unless c.zero?
  c = size <=> other.size
  return c unless c.zero?
  c = directory <=> other.directory
  return c unless c.zero?
  attributes <=> other.attributes
end

#==(other) ⇒ Object



259
260
261
# File 'lib/nexpose/asset.rb', line 259

def ==(other)
  eql?(other)
end

#directory?Boolean

Returns:

  • (Boolean)


238
239
240
# File 'lib/nexpose/asset.rb', line 238

def directory?
  directory
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


263
264
265
# File 'lib/nexpose/asset.rb', line 263

def eql?(other)
  name.eql?(other.name) && size.eql?(other.size) && directory.eql?(other.directory) && attributes.eql?(other.attributes)
end

#to_hObject



242
243
244
245
246
247
# File 'lib/nexpose/asset.rb', line 242

def to_h
  { name: name,
    size: size,
    directory: directory,
    attributes: Attributes.to_hash(attributes) }
end