Sha256: 74fa1afbc61a12b7be1b121b5f5e4bfffac5e369a8a0ff954269f9c6be92e690

Contents?: true

Size: 559 Bytes

Versions: 1

Compression:

Stored size: 559 Bytes

Contents

require 'set'

module Clef

  class Harmony < Set

    def initialize(elements)
      notes = []
      elements.each do |e|
        if Harmony === e
          notes += e.to_a
        else
          notes << e
        end
      end

      super(notes.compact.uniq)
    end

    def to_s
      if size == 1
        map {|n| n.to_s}.join(' ')
      else
        "(#{sort.map {|n| n.to_s}.join(' ')})"
      end
    end

    def +(rhs)
      if rhs.is_a?(Fixnum)
        Harmony.new(map {|n| n + rhs})
      else 
        super(rhs)
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teejayvanslyke-clef-0.0.0 lib/clef/harmony.rb