Class: Bagel::Video::ClipDataParser

Inherits:
Object
  • Object
show all
Defined in:
lib/bagel/video/clip_data_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ClipDataParser

Returns a new instance of ClipDataParser.



5
6
7
# File 'lib/bagel/video/clip_data_parser.rb', line 5

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/bagel/video/clip_data_parser.rb', line 3

def file
  @file
end

Instance Method Details

#parse_clipsObject



9
10
11
# File 'lib/bagel/video/clip_data_parser.rb', line 9

def parse_clips
  read_yaml.map { |data| parse_clip(data) }
end

#parse_points(set_number) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bagel/video/clip_data_parser.rb', line 13

def parse_points(set_number)
  read_yaml
    .select { |data| data[:type] == 'point' }
    .select { |data| data[:score].first.length == set_number }
    .map do |data|
      Point.new(
        timeframe: Timeframe.new(data[:start], data[:finish]),
        score: Score.new(sets: data[:score].first, points: data[:score].last, server: data[:server]),
        serve: Serve.new(server: data[:server], faults: data[:faults]),
        outcome: Outcome.new(winner: data[:winner], reason: data[:reason], shot: data[:shot], net: data[:net])
      )
    end
end