lib/head_music/sign.rb in head_music-0.23.1 vs lib/head_music/sign.rb in head_music-0.23.2

- old
+ new

@@ -1,12 +1,14 @@ # frozen_string_literal: true +require 'head_music/musical_symbol' + # A Sign is a symbol that modifies pitch, such as a sharp, flat, or natural. class HeadMusic::Sign include Comparable - attr_reader :identifier, :ascii, :unicode, :html_entity, :cents + attr_reader :identifier, :cents, :symbol def self.all @all ||= [ new(identifier: :sharp, ascii: '#', unicode: '♯', html_entity: '&#9839;', cents: 100), new(identifier: :flat, ascii: 'b', unicode: '♭', html_entity: '&#9837;', cents: -100), @@ -62,17 +64,22 @@ def <=>(other) other = HeadMusic::Sign.get(other) cents <=> other.cents end + delegate :ascii, :html_entity, :unicode, to: :symbol + private def initialize(attributes) @identifier = attributes[:identifier] - @ascii = attributes[:ascii] - @unicode = attributes[:unicode] - @html_entity = attributes[:html_entity] @cents = attributes[:cents] + + @symbol = HeadMusic::Symbol.new( + unicode: attributes[:unicode], + ascii: attributes[:ascii], + html_entity: attributes[:html_entity] + ) end private_class_method :new end