Class: LongTweet::IdealSplitter
- Defined in:
- lib/long_tweet/ideal_splitter.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ IdealSplitter
constructor
A new instance of IdealSplitter.
- #split ⇒ Object
Methods inherited from Splitter
Constructor Details
#initialize(text) ⇒ IdealSplitter
Returns a new instance of IdealSplitter.
4 5 6 |
# File 'lib/long_tweet/ideal_splitter.rb', line 4 def initialize text @text = text end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/long_tweet/ideal_splitter.rb', line 3 def text @text end |
Instance Method Details
#split ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/long_tweet/ideal_splitter.rb', line 8 def split a = [] ary = text.split tweet = '' while ary.length > 0 while (tweet.length + ary.first.length) < 140 tweet << "#{ary.shift} " break if ary.empty? end a << Tweet.new(tweet.strip) tweet = '' end a end |