Skip to content

Commit

Permalink
Replace hashie with rom-mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
wafcio committed Jul 1, 2016
1 parent 945ee85 commit 4967738
Show file tree
Hide file tree
Showing 20 changed files with 435 additions and 304 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: ruby
script: 'bundle exec rspec spec/functionals'
script: "bundle exec rspec spec/functionals"
rvm:
- 1.9.3
- 2.0.0
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in thetvdb_mapper.gemspec
# Specify your gem"s dependencies in thetvdb_mapper.gemspec
gemspec
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require 'bundler/gem_tasks'
require "bundler/gem_tasks"
13 changes: 6 additions & 7 deletions lib/thetvdb_mapper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'hashie'
require "rom-mapper"

module ThetvdbMapper; end

require 'thetvdb_mapper/version'
require 'thetvdb_mapper/base'
require 'thetvdb_mapper/actor'
require 'thetvdb_mapper/banner'
require 'thetvdb_mapper/episode'
require 'thetvdb_mapper/series'
require "thetvdb_mapper/version"
require "thetvdb_mapper/actor"
require "thetvdb_mapper/banner"
require "thetvdb_mapper/episode"
require "thetvdb_mapper/series"
12 changes: 6 additions & 6 deletions lib/thetvdb_mapper/actor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ThetvdbMapper::Actor < ThetvdbMapper::Base
property :id, from: 'id', with: lambda { |value| value.to_i }
property :image_path, from: 'Image'
property :name, from: 'Name'
property :role, from: 'Role'
property :sort_order, from: 'SortOrder', with: lambda { |value| value.to_i }
class ThetvdbMapper::Actor < ROM::Mapper
attribute "id", type: :integer
attribute "image_path", from: "Image"
attribute "name", from: "Name"
attribute "role", from: "Role"
attribute "sort_order", from: "SortOrder", type: :integer
end
26 changes: 13 additions & 13 deletions lib/thetvdb_mapper/banner.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class ThetvdbMapper::Banner < ThetvdbMapper::Base
property :id, from: 'id', with: lambda { |value| value.to_i }
property :path, from: 'BannerPath'
property :thumbnail_path, from: 'ThumbnailPath'
property :vignette_path, from: 'VignettePath'
property :kind, from: 'BannerType'
property :kind2, from: 'BannerType2'
property :language, from: 'Language'
property :season, from: 'Season', with: lambda { |value| value.to_i }
property :rating, from: 'Rating', with: lambda { |value| value.to_f }
property :rating_count, from: 'RatingCount', with: lambda { |value| value.to_i }
property :series_name, from: 'SeriesName'
property :colors, from: 'Colors'
class ThetvdbMapper::Banner < ROM::Mapper
attribute "id", type: :integer
attribute "path", from: "BannerPath"
attribute "thumbnail_path", from: "ThumbnailPath"
attribute "vignette_path", from: "VignettePath"
attribute "type", from: "BannerType"
attribute "type2", from: "BannerType2"
attribute "language", from: "Language"
attribute "season", from: "Season", type: :integer
attribute "rating", from: "Rating", type: :float
attribute "rating_count", from: "RatingCount", type: :integer
attribute "series_name", from: "SeriesName", type: :boolean
attribute "colors", from: "Colors"
end
5 changes: 0 additions & 5 deletions lib/thetvdb_mapper/base.rb

This file was deleted.

93 changes: 60 additions & 33 deletions lib/thetvdb_mapper/episode.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
class ThetvdbMapper::Episode < ThetvdbMapper::Base
property :id, from: 'id', with: lambda { |value| value.to_i }
property :combined_episode_number, from: 'Combined_episodenumber', with: lambda { |value| value.to_f }
property :combined_season, from: 'Combined_season', with: lambda { |value| value.to_f }
property :dvd_chapter, from: 'DVD_chapter'
property :dvd_disc_id, from: 'DVD_discid'
property :dvd_episode_number, from: 'DVD_episodenumber', with: lambda { |value| value.to_f }
property :dvd_season, from: 'DVD_season', with: lambda { |value| value.to_i }
property :directors, from: 'Director', with: lambda { |value| to_array(value) }
property :ep_img_flag, from: 'EpImgFlag', with: lambda { |value| value.to_i }
property :name, from: 'EpisodeName'
property :number, from: 'EpisodeNumber', with: lambda { |value| value.to_i }
property :first_aired, from: 'FirstAired', with: lambda { |value| Date.parse(value) }
property :guest_stars, from: 'GuestStars', with: lambda { |value| to_array(value) }
property :imdb_id, from: 'IMDB_ID'
property :language, from: 'Language'
property :overview, from: 'Overview'
property :production_code, from: 'ProductionCode'
property :rating, from: 'Rating', with: lambda { |value| value.to_f }
property :rating_count, from: 'RatingCount', with: lambda { |value| value.to_i }
property :season, from: 'SeasonNumber', with: lambda { |value| value.to_i }
property :writers, from: 'Writer', with: lambda { |value| to_array(value) }
property :absolute_number, from: 'absolute_number', with: lambda { |value| value.to_i }
property :airs_after_season, from: 'airsafter_season', with: lambda { |value| value.to_i }
property :airs_before_episode, from: 'airsbefore_episode', with: lambda { |value| value.to_i }
property :airs_before_season, from: 'airsbefore_season', with: lambda { |value| value.to_i }
property :filename_path, from: 'filename'
property :last_updated_at, from: 'lastupdated', with: lambda { |value| Time.at(value.to_i) }
property :season_id, from: 'seasonid'
property :series_id, from: 'seriesid'
property :thumbnail_added_at, from: 'thumb_added', with: lambda { |value| DateTime.parse(value) }
property :thumbnail_height, from: 'thumb_height', with: lambda { |value| value.to_i }
property :thumbnail_width, from: 'thumb_width', with: lambda { |value| value.to_i }
# class ThetvdbMapper::Episode < ThetvdbMapper::Base
# property :thumbnail_added_at, from: 'thumb_added', with: lambda { |value| DateTime.parse(value) }
# property :thumbnail_height, from: 'thumb_height', with: lambda { |value| value.to_i }
# property :thumbnail_width, from: 'thumb_width', with: lambda { |value| value.to_i }
# end

class ThetvdbMapper::Episode < ROM::Mapper
attribute "id", type: :integer
attribute "combined_episode_number", from: "Combined_episodenumber", type: :float
attribute "combined_season", from: "Combined_season", type: :float
attribute "dvd_chapter", from: "DVD_chapter"
attribute "dvd_disc_id", from: "DVD_discid"
attribute "dvd_episode_number", from: "DVD_episodenumber", type: :float
attribute "dvd_season", from: "DVD_season", type: :integer
attribute "ep_img_flag", from: "EpImgFlag", type: :integer
attribute "name", from: "EpisodeName"
attribute "number", from: "EpisodeNumber", type: :integer
attribute "imdb_id", from: "IMDB_ID"
attribute "language", from: "Language"
attribute "overview", from: "Overview"
attribute "production_code", from: "ProductionCode"
attribute "rating", from: "Rating", type: :float
attribute "rating_count", from: "RatingCount", type: :integer
attribute "season_number", from: "SeasonNumber", type: :integer
attribute "absolute_number", from: "absolute_number", type: :integer
attribute "airs_after_season", from: "airsafter_season", type: :integer
attribute "airs_before_episode", from: "airsbefore_episode", type: :integer
attribute "airs_before_season", from: "airsbefore_season", type: :integer
attribute "filename_path", from: "filename"
attribute "season_id", from: "seasonid", type: :integer
attribute "series_id", from: "seriesid", type: :integer
attribute "flagged", from: "flagged", type: :integer
attribute "mirror_updated_at", from: "mirrorupdate", type: :time
attribute "tms_export", type: :integer
attribute "thumbnail_height", from: "thumb_height", type: :integer
attribute "thumbnail_width", from: "thumb_width", type: :integer

attribute "thumbnail_added_at", from: "thumb_added" do |attr|
attr ? DateTime.parse(attr) : nil
end

attribute "first_aired", from: "FirstAired" do |attr|
attr ? Date.parse(attr) : nil
end

attribute "last_updated_at", from: "lastupdated" do |attr|
attr ? Time.at(attr.to_i) : nil
end

attribute "directors", from: "Director" do |attr|
attr.to_s.split("|").reject{ |element| element.empty? }
end

attribute "guest_stars", from: "GuestStars" do |attr|
attr.to_s.split("|").reject{ |element| element.empty? }
end

attribute "writers", from: "Writer" do |attr|
attr.to_s.split("|").reject{ |element| element.empty? }
end
end
67 changes: 41 additions & 26 deletions lib/thetvdb_mapper/series.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
class ThetvdbMapper::Series < ThetvdbMapper::Base
property :id, from: 'id', with: lambda { |value| value.to_i }
property :actors, from: 'Actors', with: lambda { |value| to_array(value) }
property :airs_day_of_week, from: 'Airs_DayOfWeek'
property :airs_time, from: 'Airs_Time'
property :content_rating, from: 'ContentRating'
property :first_aired, from: 'FirstAired', with: lambda { |value| Date.parse(value) }
property :genres, from: 'Genre', with: lambda { |value| to_array(value) }
property :imdb_id, from: 'IMDB_ID'
property :language, from: 'Language'
property :network, from: 'Network'
property :network_id, from: 'NetworkID', with: lambda { |value| value.to_i }
property :overview, from: 'Overview'
property :rating, from: 'Rating', with: lambda { |value| value.to_f }
property :rating_count, from: 'RatingCount', with: lambda { |value| value.to_i }
property :runtime, from: 'Runtime', with: lambda { |value| value.to_i }
property :name, from: 'SeriesName'
property :series_id, from: 'SeriesId', with: lambda { |value| value.to_i }
property :status, from: 'Status'
property :added_at, from: 'added', with: lambda { |value| DateTime.parse(value) }
property :added_by, from: 'addedBy'
property :banner_path, from: 'banner'
property :fanart_path, from: 'fanart'
property :last_updated_at, from: 'lastupdated', with: lambda { |value| Time.at(value.to_i) }
property :poster_path, from: 'poster'
property :zap2it_id, from: 'zap2it_id'
class ThetvdbMapper::Series < ROM::Mapper
attribute "id", type: :integer
attribute "airs_day_of_week", from: "Airs_DayOfWeek"
attribute "airs_time", from: "Airs_Time"
attribute "content_rating", from: "ContentRating"
attribute "imdb_id", from: "IMDB_ID"
attribute "language", from: "Language"
attribute "network", from: "Network"
attribute "network_id", from: "NetworkID", type: :integer
attribute "overview", from: "Overview"
attribute "rating", from: "Rating", type: :float
attribute "rating_count", from: "RatingCount", type: :integer
attribute "runtime", from: "Runtime", type: :integer
attribute "name", from: "SeriesName"
attribute "series_id", from: "SeriesID", type: :integer
attribute "status", from: "Status"
attribute "added_by", from: "addedBy"
attribute "banner_path", from: "banner"
attribute "fanart_path", from: "fanart"
attribute "poster_path", from: "poster"
attribute "zap2it_id"

attribute "added_at", from: "added" do |attr|
attr ? DateTime.parse(attr) : nil
end

attribute "first_aired", from: "FirstAired" do |attr|
attr ? Date.parse(attr) : nil
end

attribute "last_updated_at", from: "lastupdated" do |attr|
attr ? Time.at(attr.to_i) : nil
end

attribute "actors", from: "Actors" do |attr|
attr.to_s.split("|").reject{ |element| element.empty? }
end

attribute "genres", from: "Genre" do |attr|
attr.to_s.split("|").reject{ |element| element.empty? }
end
end
2 changes: 1 addition & 1 deletion lib/thetvdb_mapper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ThetvdbMapper
VERSION = '0.0.5'
VERSION = "0.0.5"
end
17 changes: 17 additions & 0 deletions spec/fixtures/actors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Actors>
<Actor>
<id>22017</id>
<Image>actors/22017.jpg</Image>
<Name>Zachary Levi</Name>
<Role>Charles &quot;Chuck&quot; Bartowski</Role>
<SortOrder>0</SortOrder>
</Actor>
<Actor>
<id>22019</id>
<Image>actors/22019.jpg</Image>
<Name>Yvonne Strahovski</Name>
<Role>Sarah Walker</Role>
<SortOrder>1</SortOrder>
</Actor>
</Actors>
54 changes: 54 additions & 0 deletions spec/fixtures/banners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Banners>
<Banner>
<id>899538</id>
<BannerPath>fanart/original/80348-55.jpg</BannerPath>
<BannerType>fanart</BannerType>
<BannerType2>1280x720</BannerType2>
<Colors>|172,157,124|184,131,113|53,53,51|</Colors>
<Language>en</Language>
<Rating>8.5000</Rating>
<RatingCount>2</RatingCount>
<SeriesName>true</SeriesName>
<ThumbnailPath>_cache/fanart/original/80348-55.jpg</ThumbnailPath>
<VignettePath>fanart/vignette/80348-55.jpg</VignettePath>
</Banner>
<Banner>
<id>877696</id>
<BannerPath>posters/80348-16.jpg</BannerPath>
<BannerType>poster</BannerType>
<BannerType2>680x1000</BannerType2>
<Language>en</Language>
<Rating>8.5556</Rating>
<RatingCount>9</RatingCount>
</Banner>
<Banner>
<id>896898</id>
<BannerPath>seasons/80348-0-2.jpg</BannerPath>
<BannerType>season</BannerType>
<BannerType2>season</BannerType2>
<Language>en</Language>
<Rating>10.0000</Rating>
<RatingCount>1</RatingCount>
<Season>0</Season>
</Banner>
<Banner>
<id>642871</id>
<BannerPath>seasonswide/80348-4.jpg</BannerPath>
<BannerType>season</BannerType>
<BannerType2>seasonwide</BannerType2>
<Language>en</Language>
<Rating>10.0000</Rating>
<RatingCount>1</RatingCount>
<Season>4</Season>
</Banner>
<Banner>
<id>893988</id>
<BannerPath>graphical/80348-g29.jpg</BannerPath>
<BannerType>series</BannerType>
<BannerType2>graphical</BannerType2>
<Language>en</Language>
<Rating>7.6667</Rating>
<RatingCount>6</RatingCount>
</Banner>
</Banners>
34 changes: 34 additions & 0 deletions spec/fixtures/episode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Data>
<Episode>
<id>332179</id>
<seasonid>27985</seasonid>
<EpisodeNumber>1</EpisodeNumber>
<EpisodeName>Chuck Versus the Intersect</EpisodeName>
<FirstAired>2007-09-24</FirstAired>
<GuestStars>Mieko Hillman|Kristine Blackport|Jim Pirri|Diana Gitelman|Mel Fair|Lynn A. Henderson|Odessa Rae|Jordan Potter|Tasha Campbell|Dale Dye|Matthew Bomer|Bruno Amato|Nicolas Pajon|Wendy Makkena</GuestStars>
<Director>McG</Director>
<Writer>Josh Schwartz|Chris Fedak</Writer>
<Overview>Chuck Bartowski is an average computer geek until files of government secrets are downloaded into his brain. He is soon scouted by the CIA and NSA to act in place of their computer.</Overview>
<ProductionCode>276025</ProductionCode>
<lastupdated>1286047470</lastupdated>
<flagged>0</flagged>
<DVD_discid></DVD_discid>
<DVD_season>1</DVD_season>
<DVD_episodenumber>1.0</DVD_episodenumber>
<DVD_chapter></DVD_chapter>
<absolute_number>1</absolute_number>
<filename>episodes/80348/332179.jpg</filename>
<seriesid>80348</seriesid>
<thumb_added></thumb_added>
<thumb_width>400</thumb_width>
<thumb_height>225</thumb_height>
<tms_export>1</tms_export>
<mirrorupdate>2013-10-08 13:25:36</mirrorupdate>
<IMDB_ID>tt1035912</IMDB_ID>
<EpImgFlag></EpImgFlag>
<Rating>7.7</Rating>
<SeasonNumber>1</SeasonNumber>
<Language>en</Language>
</Episode>
</Data>
30 changes: 30 additions & 0 deletions spec/fixtures/series.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Data>
<Series>
<id>80348</id>
<Actors>|Zachary Levi|Yvonne Strahovski|Joshua Gomez|Adam Baldwin|Bonita Friedericy|Julia Ling|Vik Sahay|Ryan McPartlin|Scott Krinsky|Mark Christopher Lawrence|Sarah Lancaster|Mekenna Melvin|Linda Hamilton|Brandon Routh|Matthew Bomer|</Actors>
<Airs_DayOfWeek>Friday</Airs_DayOfWeek>
<Airs_Time>8:00 PM</Airs_Time>
<ContentRating>TV-PG</ContentRating>
<FirstAired>2007-09-24</FirstAired>
<Genre>|Action|Adventure|Comedy|Drama|</Genre>
<IMDB_ID>tt0934814</IMDB_ID>
<Language>en</Language>
<Network>NBC</Network>
<NetworkID></NetworkID>
<Overview>Chuck Bartowski, ace computer geek at Buy More, is not in his right mind. That's a good thing. Ever since he unwittingly downloaded stolen government secrets into his brain, action, excitement and a cool secret-agent girlfriend have entered his life. It's a bad thing, too. Because now Chuck is in danger 24/7.</Overview>
<Rating>8.7</Rating>
<RatingCount>855</RatingCount>
<Runtime>60</Runtime>
<SeriesID>68724</SeriesID>
<SeriesName>Chuck</SeriesName>
<Status>Ended</Status>
<added></added>
<addedBy></addedBy>
<banner>graphical/80348-g26.jpg</banner>
<fanart>fanart/original/80348-32.jpg</fanart>
<lastupdated>1388829637</lastupdated>
<poster>posters/80348-16.jpg</poster>
<zap2it_id>EP00930779</zap2it_id>
</Series>
</Data>
Loading

0 comments on commit 4967738

Please sign in to comment.