Class: WCC::Blogs::Post

Inherits:
Object
  • 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

#rawObject (readonly)

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_allObject



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



83
84
85
# File 'lib/wcc/blogs/post.rb', line 83

def _links
  OpenStruct.new(raw['_links'] || {})
end

#author_full_nameObject



23
24
25
# File 'lib/wcc/blogs/post.rb', line 23

def author_full_name
  author&.fullName
end

#collectionObject



97
98
99
# File 'lib/wcc/blogs/post.rb', line 97

def collection
  CollectionSummary.new(raw['collection'], client: @client) if raw['collection']
end

#htmlObject



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

#metadataObject



33
34
35
# File 'lib/wcc/blogs/post.rb', line 33

def 
  WCC::Blogs::.new(raw['metadata']) if raw['metadata']
end

#published?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/wcc/blogs/post.rb', line 37

def published?
  true
end

#time_to_readObject



41
42
43
44
# File 'lib/wcc/blogs/post.rb', line 41

def time_to_read
  # TODO
  nil
end

#to_paramObject



46
47
48
# File 'lib/wcc/blogs/post.rb', line 46

def to_param
  slug.sub(%r{^/}, '')
end