Class: Blog::Author

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/models/blog/author.rb

Constant Summary collapse

DEFAULT_AVATAR =
'https://s3.eu-west-1.amazonaws.com/developer.vonage.com/vonage-logo-images/vonage-square-logo.png'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Author

Returns a new instance of Author.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 9

def initialize(attributes = {})
  @name       = attributes['name']           || 'Vonage Team Member'
  @title      = attributes['title']          || 'Vonage Team Member'
  @bio        = attributes['bio']            || ''
  @short_name = attributes['short_name']     || 'vonage_team_member'
  @email      = attributes['email']          || ''
  @image_url  = attributes['image_url']      || ''

  @author     = attributes['author']         || ''
  @alumni     = attributes['alumni']         || false
  @team       = attributes['team']           || false
  @hidden     = attributes['hidden']         || false
  @spotlight  = attributes['spotlight']      || false
  @noteworthy = attributes['noteworthy']     || ''

  @website_url  = attributes['website_url']  || ''
  @twitter      = attributes['twitter']      || ''
  @linkedin_url = attributes['linkedin_url'] || ''
  @github_url   = attributes['github_url']   || ''
  @youtube_url  = attributes['youtube_url']  || ''
  @facebook_url = attributes['facebook_url'] || ''
  @twitch_url   = attributes['twitch_url']   || ''
  @stackoverflow_url = attributes['stackoverflow_url'] || ''

  @blogposts = []
  @url       = build_avatar_url
end

Instance Attribute Details

#alumniObject (readonly)

Returns the value of attribute alumni.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def alumni
  @alumni
end

#authorObject (readonly)

Returns the value of attribute author.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def author
  @author
end

#bioObject (readonly)

Returns the value of attribute bio.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def bio
  @bio
end

#blogpostsObject (readonly)

Returns the value of attribute blogposts.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def blogposts
  @blogposts
end

#emailObject (readonly)

Returns the value of attribute email.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def email
  @email
end

#facebook_urlObject (readonly)

Returns the value of attribute facebook_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def facebook_url
  @facebook_url
end

#github_urlObject (readonly)

Returns the value of attribute github_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def github_url
  @github_url
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def hidden
  @hidden
end

#image_urlObject (readonly)

Returns the value of attribute image_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def image_url
  @image_url
end

#linkedin_urlObject (readonly)

Returns the value of attribute linkedin_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def linkedin_url
  @linkedin_url
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def name
  @name
end

#noteworthyObject (readonly)

Returns the value of attribute noteworthy.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def noteworthy
  @noteworthy
end

#short_nameObject (readonly)

Returns the value of attribute short_name.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def short_name
  @short_name
end

#spotlightObject (readonly)

Returns the value of attribute spotlight.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def spotlight
  @spotlight
end

#stackoverflow_urlObject (readonly)

Returns the value of attribute stackoverflow_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def stackoverflow_url
  @stackoverflow_url
end

#teamObject (readonly)

Returns the value of attribute team.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def team
  @team
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def title
  @title
end

#twitch_urlObject (readonly)

Returns the value of attribute twitch_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def twitch_url
  @twitch_url
end

#twitterObject (readonly)

Returns the value of attribute twitter.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def twitter
  @twitter
end

#urlObject (readonly)

Returns the value of attribute url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def url
  @url
end

#website_urlObject (readonly)

Returns the value of attribute website_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def website_url
  @website_url
end

#youtube_urlObject (readonly)

Returns the value of attribute youtube_url.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 2

def youtube_url
  @youtube_url
end

Instance Method Details

#build_all_blogposts_from_author(blogposts_json) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 37

def build_all_blogposts_from_author(blogposts_json)
  # TODO: How to handle authors with no Json info? (assay-and-roy)
  @blogposts = blogposts_json.select do |b|
    if b['author'] && b['author']['short_name'].present?
      b['author']['short_name'].downcase == @short_name.downcase
    end
  end

  @blogposts = @blogposts.map { |b| Blog::Blogpost.new b }

  self
end

#build_avatar_urlObject



50
51
52
53
54
55
56
57
58
# File 'lib/nexmo_developer/app/models/blog/author.rb', line 50

def build_avatar_url
  return DEFAULT_AVATAR if image_url.blank?

  if image_url.include?('gravatar') || image_url.include?('https://github.com/') || image_url.include?('https://ca.slack-edge.com/')
    image_url
  else
    "#{Blog::Blogpost::CLOUDFRONT_BLOG_URL}authors/#{image_url.gsub('/content/images/', '')}"
  end
end