Class: Porni::Hubs::Parser::PornParser

Inherits:
Base
  • Object
show all
Defined in:
lib/porni/hubs/parser/porn_parser.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #invalid_attributes, parse_video

Constructor Details

This class inherits a constructor from Porni::Hubs::Parser::Base

Instance Method Details

#parse_videoObject



8
9
10
11
12
13
14
# File 'lib/porni/hubs/parser/porn_parser.rb', line 8

def parse_video
  if @body["success"]
    Porni::Video.new(valid_attributes)
  else
    Porni::Video.new(invalid_attributes)
  end
end

#valid_attributesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/porni/hubs/parser/porn_parser.rb', line 16

def valid_attributes
  video = @body["result"][0]
  return invalid_attributes unless video

  {
    duration: seconds_to_hms(video["duration"]),
    title: video["title"],
    thumb: video["thumb"],
    views: video["views"],
    channel: video["channel"],
    tags: video["tags"] || [],
    pornstars: video["actors"] || [],
    valid: true,
    raw: @body
  }
end