Class: Cyclotone::Event
- Inherits:
-
Object
- Object
- Cyclotone::Event
- Defined in:
- lib/cyclotone/event.rb
Constant Summary collapse
- UNSET =
Object.new.freeze
Instance Attribute Summary collapse
-
#part ⇒ Object
readonly
Returns the value of attribute part.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#whole ⇒ Object
readonly
Returns the value of attribute whole.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #active_span ⇒ Object
- #covers_time?(time) ⇒ Boolean
- #duration ⇒ Object
- #has_whole? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(whole:, part:, value:) ⇒ Event
constructor
A new instance of Event.
- #offset ⇒ Object
- #onset ⇒ Object
- #to_h ⇒ Object
- #triggered? ⇒ Boolean
- #with_span(new_whole: UNSET, new_part: UNSET, whole: UNSET, part: UNSET) ⇒ Object
- #with_value(new_value) ⇒ Object
Constructor Details
#initialize(whole:, part:, value:) ⇒ Event
Returns a new instance of Event.
9 10 11 12 13 14 15 16 17 |
# File 'lib/cyclotone/event.rb', line 9 def initialize(whole:, part:, value:) raise ArgumentError, "part must be a TimeSpan" unless part.is_a?(TimeSpan) raise ArgumentError, "whole must be nil or a TimeSpan" unless whole.nil? || whole.is_a?(TimeSpan) @whole = whole @part = part @value = deep_freeze(value) freeze end |
Instance Attribute Details
#part ⇒ Object (readonly)
Returns the value of attribute part.
7 8 9 |
# File 'lib/cyclotone/event.rb', line 7 def part @part end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/cyclotone/event.rb', line 7 def value @value end |
#whole ⇒ Object (readonly)
Returns the value of attribute whole.
7 8 9 |
# File 'lib/cyclotone/event.rb', line 7 def whole @whole end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
72 73 74 75 76 77 |
# File 'lib/cyclotone/event.rb', line 72 def ==(other) other.is_a?(self.class) && whole == other.whole && part == other.part && value == other.value end |
#active_span ⇒ Object
41 42 43 |
# File 'lib/cyclotone/event.rb', line 41 def active_span whole || part end |
#covers_time?(time) ⇒ Boolean
45 46 47 |
# File 'lib/cyclotone/event.rb', line 45 def covers_time?(time) active_span.includes?(time) end |
#duration ⇒ Object
33 34 35 |
# File 'lib/cyclotone/event.rb', line 33 def duration whole&.duration end |
#has_whole? ⇒ Boolean
37 38 39 |
# File 'lib/cyclotone/event.rb', line 37 def has_whole? !whole.nil? end |
#hash ⇒ Object
81 82 83 |
# File 'lib/cyclotone/event.rb', line 81 def hash [self.class, whole, part, value].hash end |
#offset ⇒ Object
23 24 25 |
# File 'lib/cyclotone/event.rb', line 23 def offset whole&.stop end |
#onset ⇒ Object
19 20 21 |
# File 'lib/cyclotone/event.rb', line 19 def onset whole&.start end |
#to_h ⇒ Object
68 69 70 |
# File 'lib/cyclotone/event.rb', line 68 def to_h { whole: whole, part: part, value: value } end |
#triggered? ⇒ Boolean
27 28 29 30 31 |
# File 'lib/cyclotone/event.rb', line 27 def triggered? return false unless onset part.includes?(onset) end |
#with_span(new_whole: UNSET, new_part: UNSET, whole: UNSET, part: UNSET) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cyclotone/event.rb', line 53 def with_span(new_whole: UNSET, new_part: UNSET, whole: UNSET, part: UNSET) next_whole = if whole.equal?(UNSET) new_whole.equal?(UNSET) ? self.whole : new_whole else whole end next_part = if part.equal?(UNSET) new_part.equal?(UNSET) ? self.part : new_part else part end self.class.new(whole: next_whole, part: next_part, value: value) end |
#with_value(new_value) ⇒ Object
49 50 51 |
# File 'lib/cyclotone/event.rb', line 49 def with_value(new_value) self.class.new(whole: whole, part: part, value: new_value) end |