Skip to content

Commit

Permalink
For convenience, Timeline#[] returns an object rather than it's event…
Browse files Browse the repository at this point in the history
…. Use Timeline#events to access the events.
  • Loading branch information
Jeremy Voorhis committed Nov 1, 2008
1 parent d653ebc commit 8c47183
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/music/timeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Timeline
include Enumerable

attr_reader :events
def_delegators :@events, :[]

def self.[](*events) new(events.flatten) end

def initialize(events) @events = events end
Expand All @@ -32,6 +32,10 @@ def merge(other)
self.class.new((events + other.events).sort)
end

def [](i)
if event = @events[i] then event.object end
end

def +(other)
self.class.new(events + other.events)
end
Expand Down
5 changes: 2 additions & 3 deletions spec/score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@
end

it "should provide inherited attributes when interpreted" do
timeline = TimelineInterpreter.eval(@object)
timeline = @object.to_timeline
timeline.all? { |e| e.attributes[:slur] }.should be_true

timeline[0].object.attributes[:accented].should be_true
timeline[0].attributes[:accented].should be_true
end

it "can be mapped" do
Expand Down

0 comments on commit 8c47183

Please sign in to comment.