chopper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ v0.0.2
2
+ -- new feature: custom prepend patterns on #tweets
@@ -48,12 +48,12 @@ You can break up a string into 140 character chunks using the `#tweets` method o
48
48
 
49
49
  Chopper will detect @reply tweets (tweets that start with a twitter handle), and will prepend the handle to all tweets:
50
50
 
51
- string = "@moonmaster9000 this is a really long tweet. can you believe how long it is? i hope it's not too long, because if it goes over 140 characters, then I can't tweet it. Or can I?"
52
- string.tweets
53
- #==> [
54
- "@moonmaster9000 this is a really long tweet. can you believe how long it is? i hope it's not too long, because if it goes over 140 ...",
55
- "@moonmaster9000 characters, then I can't tweet it. Or can I?"
56
- ]
51
+ string = "@moonmaster9000 this is a really long tweet. can you believe how long it is? i hope it's not too long, because if it goes over 140 characters, then I can't tweet it. Or can I?"
52
+ string.tweets
53
+ #==> [
54
+ "@moonmaster9000 this is a really long tweet. can you believe how long it is? i hope it's not too long, because if it goes over 140 ...",
55
+ "@moonmaster9000 characters, then I can't tweet it. Or can I?"
56
+ ]
57
57
 
58
58
  ## Public Domain
59
59
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -42,3 +42,17 @@ end
42
42
  Given /^a string representing an @reply tweet less than 140 characters$/ do
43
43
  @tweet_string = "@moonmaster9000 short reply!"
44
44
  end
45
+
46
+
47
+ Given /^an @reply tweet with some numbers at the start that uniquify the tweet$/ do
48
+ @tweet_string = "@moonmaster9000 [1] this is a really long tweet. can you believe how long it is? i hope it's not too long, because if it goes over 140 characters, then I can't tweet it. Or can I?"
49
+ end
50
+
51
+ When /^I call the \#tweets method on it with a custom prepend regex that can capture the unique numbers$/ do
52
+ @tweets = @tweet_string.tweets :prepend_pattern => /^(@[^\s]+(?:\ \[\d+\])\ ).+$/
53
+ puts @tweets.inspect
54
+ end
55
+
56
+ Then /^each of those chunks should begin with the @reply and the numbers$/ do
57
+ @tweets.all? {|t| t.match /^@moonmaster9000 \[1\]/}.should be_true
58
+ end
@@ -28,3 +28,10 @@ Feature: Breaking up a string into tweets
28
28
  When I call the #tweets method on it
29
29
  Then I should get an array of strings breaking up the original string into 140 character chunks
30
30
  And each of those chunks should begin with the @reply
31
+
32
+ @focus
33
+ Scenario: Providing a custom prepend pattern
34
+ Given an @reply tweet with some numbers at the start that uniquify the tweet
35
+ When I call the #tweets method on it with a custom prepend regex that can capture the unique numbers
36
+ Then I should get an array of strings breaking up the original string into 140 character chunks
37
+ And each of those chunks should begin with the @reply and the numbers
@@ -1,8 +1,9 @@
1
1
  class String
2
2
  def tweets options={}
3
3
  return [self] if self.length <= (options[:max_length] || 140)
4
+ prepend_pattern = options[:prepend_pattern] || /^(@[^\s]+\ ).+$/
4
5
  delimiter = options[:delimiter] || "..."
5
- prepend = self.match(/^(@[^\s]+\ ).+$/)
6
+ prepend = self.match prepend_pattern
6
7
  prepend = prepend[1] if prepend
7
8
  max_length = (options[:max_length] || 140) - delimiter.length
8
9
  max_length -= prepend.length if prepend
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chopper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -60,6 +60,7 @@ extra_rdoc_files:
60
60
  - README.markdown
61
61
  files:
62
62
  - .gitignore
63
+ - CHANGELOG
63
64
  - README.markdown
64
65
  - VERSION
65
66
  - chopper.gemspec