Class: Tumblr::Post

Inherits:
Object show all
Extended by:
Query::DelegateMethods
Defined in:
lib/tumblr/objects/post.rb

Direct Known Subclasses

Answer, Audio, Chat, Link, Photo, Quote, Text, Video

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

array_attribute, #as_json, attributes, boolean_attribute, date_attribute, #dom_class, #etag, numeric_attribute, object_attribute, objectify, #serialize, #storage, string_attribute, systematize, #to_json, unserialize

Class Method Details

.build(attributes) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/tumblr/objects/post.rb', line 10

def self.build(attributes)
  klass = attributes["type"] ? Object.systematize(attributes["type"]) : self
  if klass && klass != self
    klass.build(attributes)
  else
    super
  end
end

.find(id) ⇒ Object



35
36
37
# File 'lib/tumblr/objects/post.rb', line 35

def self.find(id)
  query.id(id).first
end

.page(n) ⇒ Object



19
20
21
# File 'lib/tumblr/objects/post.rb', line 19

def self.page(n)
  query.page([1, n.to_i].max)
end

.per_page(n) ⇒ Object



23
24
25
# File 'lib/tumblr/objects/post.rb', line 23

def self.per_page(n)
  query.per_page(n)
end

.tagged_with(tag) ⇒ Object



31
32
33
# File 'lib/tumblr/objects/post.rb', line 31

def self.tagged_with(tag)
  query.tag(tag)
end

.type(type) ⇒ Object



27
28
29
# File 'lib/tumblr/objects/post.rb', line 27

def self.type(type)
  query.type(type)
end

Instance Method Details

#commitObject



39
40
41
42
43
44
45
# File 'lib/tumblr/objects/post.rb', line 39

def commit
  super
  tags.each do |tag|
    Redis::Set.new("#{Blog::STORAGE_KEY}:tags", Tumblr.config.redis) << tag.downcase
    Redis::List.new("#{Blog::STORAGE_KEY}:tags:#{tag.downcase.underscore}", Tumblr.config.redis) << slug
  end
end

#html?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/tumblr/objects/post.rb', line 47

def html?
  format == "html"
end

#markdown?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/tumblr/objects/post.rb', line 51

def markdown?
  format == "markdown"
end

#slugObject



55
56
57
# File 'lib/tumblr/objects/post.rb', line 55

def slug
  @slug ||= title.parameterize
end

#to_paramObject



59
60
61
# File 'lib/tumblr/objects/post.rb', line 59

def to_param
  slug
end