VideoData: Extract video data from csv files
How to Install
Use Rubygems to install video_data:
$ gem install video_data
From source
$ git clone [email protected]:hectoregm/video_data.git
$ cd video_data && bundle install && bundle exec 'rake install'
Usage
require 'video_data'
parser = VideoData.new('video_data.csv') # Get parser to extract data
attrs = parser.attributes # Get the attributes that are defined in the csv
videos = parser.videos # Get an array of videos from csv data
# Calls for VideoData::Video
video = videos[0]
video.name # Outputs name of video
video.date # Outputs date of video
video.celebrity # Outputs celebrity of video
video. # Outputs an array of active tags
video[:date] # Hash like access to data
video.to_s # Ouputs a human readable string of the video data
video.eye_winged? # Dynamic predicates for each tag
Tests
$ rake spec
Documentation
$ rake rdoc
Description of Solution
Decided from the first moment to make it a gem to make it easy to use and install. I decided to separate in two clases the main responsabilites to resolve the problem:
- VideoData::Parser: Read the csv file and get the columns(attributes) and the data. Have a convenient method to get all the videos in the file. Handle convertion of : to _ for tags.
- VideoData::Video: From the attributes extracted in the parser and the row data define the attributes of the video.
The gotchas are when pairing the attributes and the row data, order is vital to associate each value. Some data is saved as is (:videos, :date, :celebrity) while each tag is associated to a boolean value.
VideoData::Video has easy access to the data using #name, #date, #celebrity and #tags. Bonus hash-like access is a natural addition given that internally the data is stored in a hash.
So recaping we have VideoData::Parser that reads the file, separates the columns and the data, then delegates the pairing of attributes and row data to VideoData::Video, finally internally it stores the video data in a Hash.
Brownie points for adding dynamic predicates for each defined tag.
A convenient ::new in the top module to jump start the extraction.