class Shin::Data::Sfi

Public Instance Methods

info(params={}) click to toggle source

Info

# File lib/shin/data/sfi.rb, line 58
def info(params={})
  raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
  
  # Response
  response = Base.get('http://www.sfi.se/sv/svensk-filmdatabas/Item/?type=MOVIE&itemid=' + params[:id].to_s)
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Nokogiri parse
  @main_noko = Nokogiri::HTML response.body rescue nil
  
  # Can't be nil
  if @main_noko != nil
    # Data
    @swedish_title = @main_noko.css('td#ctl00_Full_Main_ctl00_SwedishTitleCell').text.gsub(/Mer$/, "").strip rescue nil
    @description = @main_noko.css('div#ctl00_Full_Main_ctl00_StorySummary').text.strip rescue nil
    @swedish_premiere = @main_noko.css('td#ctl00_Full_Main_ctl00_SwedishPremiereCell').text rescue nil
    @age_limit = @main_noko.css('span#ctl00_Full_Main_ctl00_AgeLimitContent').text.strip rescue nil
    
    {id: params[:id].to_i, swedish_title: @swedish_title, swedish_premiere: @swedish_premiere, description: @description, age_limit: @age_limit}.to_hashugar
  else
    raise NotValid, "Nokogiri failed to parse the HTML."
  end
end
new() click to toggle source
# File lib/shin/data/sfi.rb, line 8
def new
  self
end
titles(params={}) click to toggle source

Titles

# File lib/shin/data/sfi.rb, line 83
def titles(params={})
  raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
  
  # Response
  response = Base.get('http://www.sfi.se/en-GB/svensk-filmdatabas/Item/?type=MOVIE&iv=Titles&itemid=' + params[:id].to_s)
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Nokogiri parse
  @main_noko = Nokogiri::HTML response.body rescue nil
  
  # Can't be nil
  if @main_noko != nil
    @array = []
    
    @main_noko.css('table#ctl00_Full_Main_ctl00_TitlesTable > tr').map do |e|
      @type = e.css('th').text.strip.gsub(/\:$/, "") rescue nil
      @title = e.css('td').text.strip rescue nil
          
      @array << {type: @type, title: @title}
    end
    
    @array.to_hashugar
  else
    raise NotValid, "Nokogiri failed to parse the HTML."
  end
end