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.



105
106
107
108
# File 'lib/license_finder/packages/npm_package.rb', line 105

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



103
104
105
# File 'lib/license_finder/packages/npm_package.rb', line 103

def name
  @name
end

#versionObject

Returns the value of attribute version.



103
104
105
# File 'lib/license_finder/packages/npm_package.rb', line 103

def version
  @version
end

Class Method Details

.from_hash(hash) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/license_finder/packages/npm_package.rb', line 110

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

  Identifier.new(name, version)
end

Instance Method Details

#<=>(other) ⇒ Object



130
131
132
133
# File 'lib/license_finder/packages/npm_package.rb', line 130

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

#==(other) ⇒ Object



118
119
120
# File 'lib/license_finder/packages/npm_package.rb', line 118

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/license_finder/packages/npm_package.rb', line 122

def eql?(other)
  self == other
end

#hashObject



126
127
128
# File 'lib/license_finder/packages/npm_package.rb', line 126

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

#to_sObject



135
136
137
# File 'lib/license_finder/packages/npm_package.rb', line 135

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