lib/head_music/octave.rb in head_music-0.17.0 vs lib/head_music/octave.rb in head_music-0.18.0
- old
+ new
@@ -1,5 +1,8 @@
+# frozen_string_literal: true
+
+# The Octave identifier is a number used in scientific pitch notation.
class HeadMusic::Octave
include Comparable
DEFAULT = 4
@@ -7,21 +10,20 @@
from_number(identifier) || from_name(identifier) || default
end
def self.from_number(identifier)
return nil unless identifier.to_s == identifier.to_i.to_s
- return nil unless (-2..12).include?(identifier.to_i)
+ return nil unless (-2..12).cover?(identifier.to_i)
@octaves ||= {}
@octaves[identifier.to_i] ||= new(identifier.to_i)
end
def self.from_name(string)
- if string.to_s.match(HeadMusic::Spelling::MATCHER)
- _letter, _sign, octave_string = string.to_s.match(HeadMusic::Spelling::MATCHER).captures
- @octaves ||= {}
- @octaves[octave_string.to_i] ||= new(octave_string.to_i) if octave_string
- end
+ return unless string.to_s.match?(HeadMusic::Spelling::MATCHER)
+ _letter, _sign, octave_string = string.to_s.match(HeadMusic::Spelling::MATCHER).captures
+ @octaves ||= {}
+ @octaves[octave_string.to_i] ||= new(octave_string.to_i) if octave_string
end
def self.default
@octaves[DEFAULT] ||= new(DEFAULT)
end
@@ -32,10 +34,10 @@
def initialize(number)
@number ||= number
end
def <=>(other)
- self.to_i <=> other.to_i
+ to_i <=> other.to_i
end
private_class_method :new
end