Class: MetalArchives::Parsers::Year

Inherits:
Base
  • Object
show all
Defined in:
lib/metal_archives/parsers/year.rb

Overview

Year range parser

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Object

Parse year range

Returns Range of Integer



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/metal_archives/parsers/year.rb', line 14

def self.parse(input)
  return if input.blank?

  components = input
    .split("-")
    .map(&:to_i)
    .map { |y| y.zero? ? nil : y }

  return if components.empty?

  # Set end if only one year
  components << components.first if components.count == 1

  components[0]..components[1]
end