Class: LongTweet::Splitter

Inherits:
Object
  • Object
show all
Defined in:
lib/long_tweet/splitter.rb

Direct Known Subclasses

IdealSplitter, NaiveSplitter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Splitter

Returns a new instance of Splitter.



4
5
6
7
# File 'lib/long_tweet/splitter.rb', line 4

def initialize text
  @text = text
  @splitter = set_splitter
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/long_tweet/splitter.rb', line 3

def text
  @text
end

Instance Method Details

#set_splitterObject



9
10
11
12
13
14
15
# File 'lib/long_tweet/splitter.rb', line 9

def set_splitter
  if text.split.any? {|e| e.length > 140 }
    NaiveSplitter.new text
  else
    IdealSplitter.new text
  end
end

#splitObject



23
24
25
# File 'lib/long_tweet/splitter.rb', line 23

def split
  @splitter.split
end

#tweet_countObject



17
18
19
20
21
# File 'lib/long_tweet/splitter.rb', line 17

def tweet_count
  tweet_count = text.length/140
  tweet_count += 1 if text.length.modulo(140) > 0
  tweet_count
end