class Bagel::Video::ClipDataParser

Public Class Methods

new(file) click to toggle source
# File lib/bagel/video/clip_data_parser.rb, line 5
def initialize(file)
  @file = file
end

Public Instance Methods

parse_clips() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

parse_clip(data) click to toggle source
# File lib/bagel/video/clip_data_parser.rb, line 33
def parse_clip(data)
  builder = ClipBuilderFactory.for(data[:type].to_sym, data)
  director = ClipDirector.new(builder)
  director.build_clip
end
read_yaml() click to toggle source
# File lib/bagel/video/clip_data_parser.rb, line 29
def read_yaml
  YAML.safe_load_file(file, symbolize_names: true)
end