Class: TDRB::Result
- Inherits:
-
Object
- Object
- TDRB::Result
- Defined in:
- lib/tdrb/result.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#movements ⇒ Object
readonly
Returns the value of attribute movements.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#occurred_at ⇒ Object
readonly
Returns the value of attribute occurred_at.
-
#performances ⇒ Object
readonly
Returns the value of attribute performances.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #add_performance(performance, metadata: {}, notes: []) ⇒ Object
-
#initialize(movements: ::Set.new, occurred_at: nil, performances: [], source: "") ⇒ Result
constructor
A new instance of Result.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(movements: ::Set.new, occurred_at: nil, performances: [], source: "") ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tdrb/result.rb', line 13 def initialize( movements: ::Set.new, occurred_at: nil, performances: [], source: "" ) @metadata = {} @movements = movements @notes = [] @occurred_at = occurred_at @performances = performances @source = source end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/tdrb/result.rb', line 6 def @metadata end |
#movements ⇒ Object (readonly)
Returns the value of attribute movements.
6 7 8 |
# File 'lib/tdrb/result.rb', line 6 def movements @movements end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
6 7 8 |
# File 'lib/tdrb/result.rb', line 6 def notes @notes end |
#occurred_at ⇒ Object (readonly)
Returns the value of attribute occurred_at.
6 7 8 |
# File 'lib/tdrb/result.rb', line 6 def occurred_at @occurred_at end |
#performances ⇒ Object (readonly)
Returns the value of attribute performances.
6 7 8 |
# File 'lib/tdrb/result.rb', line 6 def performances @performances end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/tdrb/result.rb', line 6 def source @source end |
Instance Method Details
#add_performance(performance, metadata: {}, notes: []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tdrb/result.rb', line 27 def add_performance(performance, metadata: {}, notes: []) raise TypeError.new("Not a performance") if !performance.is_a? Performance movements.add(performance.movement) performance. = performance.notes = notes performance.sequence = performances.count performances << performance end |
#to_h ⇒ Object
39 40 41 42 43 44 |
# File 'lib/tdrb/result.rb', line 39 def to_h @hash ||= instance_variables.each_with_object({}) do |iv, h| h[iv[1..].to_sym] = instance_variable_get(iv) end end |
#to_json ⇒ Object
46 47 48 |
# File 'lib/tdrb/result.rb', line 46 def to_json @json ||= to_h.to_json end |