Class: Frinkiac::Screencap
- Inherits:
-
Object
- Object
- Frinkiac::Screencap
- Defined in:
- lib/frinkiac/screencap.rb
Instance Attribute Summary collapse
-
#episode ⇒ Object
readonly
Returns the value of attribute episode.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #caption ⇒ Object
- #image_url ⇒ Object
-
#initialize(attributes) ⇒ Screencap
constructor
A new instance of Screencap.
- #meme_url(caption = nil) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Screencap
Returns a new instance of Screencap.
14 15 16 17 18 |
# File 'lib/frinkiac/screencap.rb', line 14 def initialize(attributes) @id = attributes['Id'] @episode = attributes['Episode'] @timestamp = attributes['Timestamp'] end |
Instance Attribute Details
#episode ⇒ Object (readonly)
Returns the value of attribute episode.
12 13 14 |
# File 'lib/frinkiac/screencap.rb', line 12 def episode @episode end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/frinkiac/screencap.rb', line 12 def id @id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
12 13 14 |
# File 'lib/frinkiac/screencap.rb', line 12 def @timestamp end |
Class Method Details
.random(query) ⇒ Object
47 48 49 50 |
# File 'lib/frinkiac/screencap.rb', line 47 def self.random(query) screencaps = search(query) screencaps[rand(screencaps.size)] if screencaps.any? end |
.search(query) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/frinkiac/screencap.rb', line 40 def self.search(query) response = Faraday.get("#{API_URL}?q=#{query}") screencaps = JSON.parse(response.body) screencaps.map { |attributes| new(attributes) } end |
Instance Method Details
#caption ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/frinkiac/screencap.rb', line 31 def caption @caption ||= begin response = Faraday.get("#{CAPTION_URL}?e=#{episode}&t=#{}") body = JSON.parse(response.body) format_captions(body['Subtitles'].collect { |s| s['Content'] }) end end |
#image_url ⇒ Object
20 21 22 |
# File 'lib/frinkiac/screencap.rb', line 20 def image_url "#{SITE_URL}/img/#{episode}/#{}.jpg" end |
#meme_url(caption = nil) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/frinkiac/screencap.rb', line 24 def meme_url(caption = nil) caption = self.caption if caption.nil? caption = caption.join("\n") if caption.is_a?(Array) "#{SITE_URL}/meme/#{episode}/#{}.jpg?b64lines=#{Base64.strict_encode64 caption}" end |