Class: TDRB::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/tdrb/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/tdrb/result.rb', line 6

def 
  @metadata
end

#movementsObject (readonly)

Returns the value of attribute movements.



6
7
8
# File 'lib/tdrb/result.rb', line 6

def movements
  @movements
end

#notesObject (readonly)

Returns the value of attribute notes.



6
7
8
# File 'lib/tdrb/result.rb', line 6

def notes
  @notes
end

#occurred_atObject (readonly)

Returns the value of attribute occurred_at.



6
7
8
# File 'lib/tdrb/result.rb', line 6

def occurred_at
  @occurred_at
end

#performancesObject (readonly)

Returns the value of attribute performances.



6
7
8
# File 'lib/tdrb/result.rb', line 6

def performances
  @performances
end

#sourceObject (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

Raises:

  • (TypeError)


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_hObject



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_jsonObject



46
47
48
# File 'lib/tdrb/result.rb', line 46

def to_json
  @json ||= to_h.to_json
end