Class: LicenseFinder::NpmPackage::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/packages/npm_package.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ Identifier

Returns a new instance of Identifier.



152
153
154
155
# File 'lib/license_finder/packages/npm_package.rb', line 152

def initialize(name, version)
  @name = name
  @version = version
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



150
151
152
# File 'lib/license_finder/packages/npm_package.rb', line 150

def name
  @name
end

#versionObject

Returns the value of attribute version.



150
151
152
# File 'lib/license_finder/packages/npm_package.rb', line 150

def version
  @version
end

Class Method Details

.from_hash(hash) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/license_finder/packages/npm_package.rb', line 157

def self.from_hash(hash)
  name = hash['name']
  version = hash['version']
  return nil if name.nil? || name.empty? || version.nil? || version.empty?

  Identifier.new(name, version)
end

Instance Method Details

#<=>(other) ⇒ Object



177
178
179
180
# File 'lib/license_finder/packages/npm_package.rb', line 177

def <=>(other)
  sort_name = @name <=> other.name
  sort_name.zero? ? @version <=> other.version : sort_name
end

#==(other) ⇒ Object



165
166
167
# File 'lib/license_finder/packages/npm_package.rb', line 165

def ==(other)
  other.is_a?(Identifier) && @name == other.name && @version == other.version
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/license_finder/packages/npm_package.rb', line 169

def eql?(other)
  self == other
end

#hashObject



173
174
175
# File 'lib/license_finder/packages/npm_package.rb', line 173

def hash
  [@name, @version].hash
end

#to_sObject



182
183
184
# File 'lib/license_finder/packages/npm_package.rb', line 182

def to_s
  "#{@name} - #{@version}"
end