Class: Tumblargh::Resource::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/tumblargh/resource/post.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #context

Instance Method Summary collapse

Methods inherited from Base

#method_missing

Constructor Details

#initialize(attrs, blog) ⇒ Post

Returns a new instance of Post.



6
7
8
9
# File 'lib/tumblargh/resource/post.rb', line 6

def initialize(attrs, blog)
  @blog = blog
  super(attrs)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tumblargh::Resource::Base

Instance Method Details

#dateObject



24
25
26
# File 'lib/tumblargh/resource/post.rb', line 24

def date
  @date ||= @attributes[:date].to_time
end

#dialogueObject



60
61
62
# File 'lib/tumblargh/resource/post.rb', line 60

def dialogue
  @dialogue ||= (@attributes[:dialogue] || []).map { |t| Dialogue.new(t) }
end

#notesObject



51
52
53
54
# File 'lib/tumblargh/resource/post.rb', line 51

def notes
  @notes || self.notes = API.notes(@blog.domain, :id => id)
  @notes
end

#notes=(ary) ⇒ Object



56
57
58
# File 'lib/tumblargh/resource/post.rb', line 56

def notes=(ary)
  @notes = ary.map { |n| Note.new(n) }
end

#photo_url(size = 500) ⇒ Object



28
29
30
31
# File 'lib/tumblargh/resource/post.rb', line 28

def photo_url(size=500)
  return nil if (photos.nil? || photos.empty?)
  photos.first.photo_url size
end

#photosObject



64
65
66
# File 'lib/tumblargh/resource/post.rb', line 64

def photos
  @photos ||= (@attributes[:photos] || []).map { |p| Photo.new(p) }
end

#tagsObject



45
46
47
48
49
# File 'lib/tumblargh/resource/post.rb', line 45

def tags
  @tags ||= @attributes[:tags].map do |t|
    Tag.new({ :name => t })
  end
end

#titleObject

Override method_missing so this does not propagate



20
21
22
# File 'lib/tumblargh/resource/post.rb', line 20

def title
  @attributes[:title]
end

#typeObject



11
12
13
14
15
16
17
# File 'lib/tumblargh/resource/post.rb', line 11

def type
  if @attributes[:type] == 'photo'
    photos.size > 1 ? 'photoset' : 'photo'
  else
    @attributes[:type]
  end
end

#video(size = 500) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tumblargh/resource/post.rb', line 33

def video(size=500)
  return nil if (player.nil? || player.empty?)

  size = size.to_i

  res = player.select do |p|
    p[:width] == size
  end

  res.empty? ? nil : res.first[:embed_code]
end