Class: Tweet

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/tweet.rb,
lib/tweet/tag_too_long.rb

Overview

Extending lib/tweet

Defined Under Namespace

Classes: TagTooLong

Constant Summary collapse

C =

Shortcut for Contracts

Contracts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link) ⇒ Tweet

Returns a new instance of Tweet.



15
16
17
18
# File 'lib/tweet.rb', line 15

def initialize(link)
  @link = link
  @post = "| #{@link}"
end

Instance Attribute Details

Returns the value of attribute link.



8
9
10
# File 'lib/tweet.rb', line 8

def link
  @link
end

#postObject

Returns the value of attribute post.



9
10
11
# File 'lib/tweet.rb', line 9

def post
  @post
end

Instance Method Details

#add(tag) ⇒ Object

Add tag to @post



22
23
24
25
26
27
28
29
# File 'lib/tweet.rb', line 22

def add(tag)
  temp_post = "| #{tag} #{@post}"
  if temp_post.length <= 140
    @post = "| #{tag} #{@post}"
  else
    fail Tweet::TagTooLong
  end
end

#to_sObject

Output the post



33
34
35
# File 'lib/tweet.rb', line 33

def to_s
  @post.to_s
end