Class: EndOfLife::RubyVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/end_of_life/ruby_version.rb,
lib/end_of_life/ruby_version/parser.rb

Defined Under Namespace

Modules: Parser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string, eol_date: nil) ⇒ RubyVersion

Returns a new instance of RubyVersion.



46
47
48
49
50
51
# File 'lib/end_of_life/ruby_version.rb', line 46

def initialize(version_string, eol_date: nil)
  @version = Gem::Version.new(version_string)
  @eol_date = eol_date

  freeze
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



44
45
46
# File 'lib/end_of_life/ruby_version.rb', line 44

def version
  @version
end

Class Method Details

.eol_versions_at(date) ⇒ Object



16
17
18
# File 'lib/end_of_life/ruby_version.rb', line 16

def eol_versions_at(date)
  all_versions.filter { |version| version.eol_date <= date }
end

.from_file(file_name:, content:, parser: Parser) ⇒ Object



12
13
14
# File 'lib/end_of_life/ruby_version.rb', line 12

def from_file(file_name:, content:, parser: Parser)
  parser.parse_file(file_name: file_name, content: content)
end

.latest_eol(at: Date.today) ⇒ Object



20
21
22
# File 'lib/end_of_life/ruby_version.rb', line 20

def latest_eol(at: Date.today)
  eol_versions_at(at).max
end

Instance Method Details

#<=>(other) ⇒ Object



57
58
59
# File 'lib/end_of_life/ruby_version.rb', line 57

def <=>(other)
  @version <=> other.version
end

#eol?(at: Date.today) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/end_of_life/ruby_version.rb', line 53

def eol?(at: Date.today)
  self <= RubyVersion.latest_eol(at: at)
end

#to_sObject



61
62
63
# File 'lib/end_of_life/ruby_version.rb', line 61

def to_s
  @version.to_s
end