Class: LicenseFinder::NpmPackage::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/package_managers/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.



89
90
91
92
# File 'lib/license_finder/package_managers/npm_package.rb', line 89

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



87
88
89
# File 'lib/license_finder/package_managers/npm_package.rb', line 87

def name
  @name
end

#versionObject

Returns the value of attribute version.



87
88
89
# File 'lib/license_finder/package_managers/npm_package.rb', line 87

def version
  @version
end

Class Method Details

.from_hash(hash) ⇒ Object



94
95
96
97
98
# File 'lib/license_finder/package_managers/npm_package.rb', line 94

def self.from_hash(hash)
  name = hash['name'] || ''
  version = hash['version'] || ''
  Identifier.new(name, version)
end

Instance Method Details

#<=>(other) ⇒ Object



112
113
114
115
# File 'lib/license_finder/package_managers/npm_package.rb', line 112

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

#==(other) ⇒ Object



100
101
102
# File 'lib/license_finder/package_managers/npm_package.rb', line 100

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/license_finder/package_managers/npm_package.rb', line 104

def eql?(other)
  self == other
end

#hashObject



108
109
110
# File 'lib/license_finder/package_managers/npm_package.rb', line 108

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

#to_sObject



117
118
119
# File 'lib/license_finder/package_managers/npm_package.rb', line 117

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