Class: WCC::Blogs::Post
- Inherits:
-
Object
show all
- Extended by:
- Utils
- Defined in:
- lib/wcc/blogs/post.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utils
camelcase, define_camelcase_alias
Constructor Details
#initialize(raw, client: WCC::Blogs.client) ⇒ Post
Returns a new instance of Post.
18
19
20
21
|
# File 'lib/wcc/blogs/post.rb', line 18
def initialize(raw, client: WCC::Blogs.client)
@raw = raw
@client = client
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
16
17
18
|
# File 'lib/wcc/blogs/post.rb', line 16
def raw
@raw
end
|
Class Method Details
.find(slug) ⇒ Object
8
9
10
|
# File 'lib/wcc/blogs/post.rb', line 8
def self.find(slug)
new(WCC::Blogs.client.blog_show(slug).raw, client: WCC::Blogs.client)
end
|
.find_all ⇒ Object
12
13
14
|
# File 'lib/wcc/blogs/post.rb', line 12
def self.find_all
PostSummary.find_all.map(&:full_post)
end
|
Instance Method Details
#_links ⇒ Object
83
84
85
|
# File 'lib/wcc/blogs/post.rb', line 83
def _links
OpenStruct.new(raw['_links'] || {})
end
|
#author_full_name ⇒ Object
23
24
25
|
# File 'lib/wcc/blogs/post.rb', line 23
def author_full_name
author&.fullName
end
|
#collection ⇒ Object
97
98
99
|
# File 'lib/wcc/blogs/post.rb', line 97
def collection
CollectionSummary.new(raw['collection'], client: @client) if raw['collection']
end
|
#html ⇒ Object
27
28
29
30
31
|
# File 'lib/wcc/blogs/post.rb', line 27
def html
@html ||= @client.get(_links.fragment)
.body
.force_encoding('UTF-8')
end
|
33
34
35
|
# File 'lib/wcc/blogs/post.rb', line 33
def metadata
WCC::Blogs::Metadata.new(raw['metadata']) if raw['metadata']
end
|
#published? ⇒ Boolean
37
38
39
|
# File 'lib/wcc/blogs/post.rb', line 37
def published?
true
end
|
#time_to_read ⇒ Object
41
42
43
44
|
# File 'lib/wcc/blogs/post.rb', line 41
def time_to_read
nil
end
|
#to_param ⇒ Object
46
47
48
|
# File 'lib/wcc/blogs/post.rb', line 46
def to_param
slug.sub(%r{^/}, '')
end
|