ping 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cc7737e01bee08f3abaee44f739b61293b21696
4
- data.tar.gz: 91eb21315170088ccc7c87c6d3b060cac1b508df
3
+ metadata.gz: 036d44b633820e66e18e6711acace01648034351
4
+ data.tar.gz: d27bc8570003420c9507d30fbf48f5f694cffb44
5
5
  SHA512:
6
- metadata.gz: 21b1b06d39a3de9425cb465b4885ac70ec5125b272a5051f380b086ebe4359e6f4ed12d66162168950f78cf19e84662da9b7eaabdedbec9ce6632c6c1111a4f5
7
- data.tar.gz: 7db2f21c90ec9af0cdc0c82a1f4d2ac1166cc2220c7cabdf20ded4f071b93d814b8005db9b06b93768998c66a780f46ab51fd8af1e7d575628ead97787950da3
6
+ metadata.gz: 7cbee0d6277080a360aa6a50b119756350692c951c41d9a5fc4576898dc2791d3982bfb9889aae3eb67ab39787c78d4dc703217bb29318157f5c8cd2b18be239
7
+ data.tar.gz: 4452025bfd32322e299a0c9140b202621ed6566d1c94a25276530d270fa05e64d3b51b4de1b9f12b7cc27d4bdc1abde25f1c8be78f2f60fa2ee3f4341c3e8a13
data/lib/ping/issue.rb ADDED
@@ -0,0 +1,51 @@
1
+ module Ping
2
+ class Issue
3
+ attr_reader :qualifier, :repository, :number
4
+
5
+ Qualifiers = /
6
+ close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved|
7
+ need|needs|needed|require|requires|required
8
+ /ix
9
+
10
+ RepositoryName = /[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*/
11
+
12
+ Pattern = /
13
+ (?:^|\W) # beginning of string or non-word char
14
+ (?:(#{Qualifiers})(?:\s))? # qualifier (optional)
15
+ (#{RepositoryName})? # repository name (optional)
16
+ \#(\d+) # issue number
17
+ (?=
18
+ \.+[ \t\W]| # dots followed by space or non-word character
19
+ \.+$| # dots at end of line
20
+ [^0-9a-zA-Z_.]| # non-word character except dot
21
+ $ # end of line
22
+ )
23
+ /ix
24
+
25
+ # See http://rubular.com/r/LxWUfwmPhM
26
+
27
+ def initialize(qualifier, repository, number)
28
+ @qualifier = qualifier
29
+ @repository = repository
30
+ @number = number
31
+ end
32
+
33
+ def self.extract(text)
34
+ text.scan(Pattern).map do |match|
35
+ self.new(*match)
36
+ end
37
+ end
38
+
39
+ def ==(other)
40
+ other.to_i == to_i
41
+ end
42
+
43
+ def to_i
44
+ number.to_i
45
+ end
46
+
47
+ def to_s
48
+ number.to_s
49
+ end
50
+ end
51
+ end
data/lib/ping/mention.rb CHANGED
@@ -2,7 +2,7 @@ module Ping
2
2
  class Mention
3
3
  attr_reader :username
4
4
 
5
- PATTERN = /
5
+ Pattern = /
6
6
  (?:^|\W) # beginning of string or non-word char
7
7
  @((?>[a-z0-9][a-z0-9-]*)) # @username
8
8
  (?!\/) # without a trailing slash
@@ -19,7 +19,7 @@ module Ping
19
19
  end
20
20
 
21
21
  def self.extract(text)
22
- text.scan(PATTERN).flatten.
22
+ text.scan(Pattern).flatten.
23
23
  map(&:downcase).uniq.map do |username|
24
24
  self.new(username)
25
25
  end
data/lib/ping/parser.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "ping/mention"
2
+ require "ping/issue"
2
3
 
3
4
  module Ping
4
5
  class Parser
@@ -11,5 +12,9 @@ module Ping
11
12
  def mentions
12
13
  Ping::Mention.extract(text)
13
14
  end
15
+
16
+ def issues
17
+ Ping::Issue.extract(text)
18
+ end
14
19
  end
15
20
  end
data/lib/ping/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ping
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class Ping::IssueTest < MiniTest::Test
4
+ context "#==" do
5
+ should "compare with integers" do
6
+ issue = Ping::Issue.new("fixes", "codetree/codetree", "123")
7
+ assert issue == 123
8
+ end
9
+
10
+ should "compare with strings" do
11
+ issue = Ping::Issue.new("fixes", "codetree/codetree", "123")
12
+ assert issue == "123"
13
+ end
14
+
15
+ should "compare with issues" do
16
+ issue = Ping::Issue.new("fixes", "codetree/codetree", "123")
17
+ assert issue == Ping::Issue.new(nil, "codetree/codetree", "123")
18
+ end
19
+ end
20
+
21
+ context "#to_s" do
22
+ should "return the issue number" do
23
+ issue = Ping::Issue.new("Fixes", "codetree/codetree", "123")
24
+ assert_equal "123", issue.to_s
25
+ end
26
+ end
27
+
28
+ context "#to_i" do
29
+ should "return the integer issue number" do
30
+ issue = Ping::Issue.new("Fixes", "codetree/codetree", "123")
31
+ assert_equal 123, issue.to_i
32
+ end
33
+ end
34
+ end
@@ -15,4 +15,110 @@ class Ping::ParserTest < MiniTest::Test
15
15
  assert_equal 1, parser.mentions.length
16
16
  end
17
17
  end
18
+
19
+ context "#issues" do
20
+ should "extract single issue references" do
21
+ text = "See #43"
22
+ parser = Ping::Parser.new(text)
23
+ issue = parser.issues.first
24
+
25
+ assert_equal nil, issue.qualifier
26
+ assert_equal nil, issue.repository
27
+ assert_equal "43", issue.number
28
+ end
29
+
30
+ should "extract single issue references followed by a period" do
31
+ text = "See #43."
32
+ parser = Ping::Parser.new(text)
33
+ issue = parser.issues.first
34
+
35
+ assert_equal nil, issue.qualifier
36
+ assert_equal nil, issue.repository
37
+ assert_equal "43", issue.number
38
+ end
39
+
40
+ should "extract close qualifiers" do
41
+ %w{fix fixes fixed close closes closed resolve resolves resolved}.each do |q|
42
+ text = "#{q} #55"
43
+ parser = Ping::Parser.new(text)
44
+ issue = parser.issues.first
45
+
46
+ assert_equal q, issue.qualifier
47
+ assert_equal nil, issue.repository
48
+ assert_equal "55", issue.number
49
+ end
50
+ end
51
+
52
+ should "extract dependency qualifiers" do
53
+ %w{need needs needed require requires required}.each do |q|
54
+ text = "#{q} #123"
55
+ parser = Ping::Parser.new(text)
56
+ issue = parser.issues.first
57
+
58
+ assert_equal q, issue.qualifier
59
+ assert_equal nil, issue.repository
60
+ assert_equal "123", issue.number
61
+ end
62
+ end
63
+
64
+ should "extract repository" do
65
+ text = "codetree/codetree#43"
66
+ parser = Ping::Parser.new(text)
67
+ issue = parser.issues.first
68
+
69
+ assert_equal nil, issue.qualifier
70
+ assert_equal "codetree/codetree", issue.repository
71
+ assert_equal "43", issue.number
72
+ end
73
+
74
+ should "extract repository with qualifier" do
75
+ text = "Fixes codetree/codetree#43"
76
+ parser = Ping::Parser.new(text)
77
+ issue = parser.issues.first
78
+
79
+ assert_equal "Fixes", issue.qualifier
80
+ assert_equal "codetree/codetree", issue.repository
81
+ assert_equal "43", issue.number
82
+ end
83
+
84
+ should "extract multiple references" do
85
+ text = "You should look at #2 and #4 because #5 fixes codetree/codetree#6"
86
+ parser = Ping::Parser.new(text)
87
+
88
+ assert parser.issues.include?(2)
89
+ assert parser.issues.include?(4)
90
+ assert parser.issues.include?(5)
91
+ assert parser.issues.include?(6)
92
+ end
93
+
94
+ should "not extract similar non-qualifiers" do
95
+ text = "afixes #43"
96
+ parser = Ping::Parser.new(text)
97
+ issue = parser.issues.first
98
+
99
+ assert_equal nil, issue.qualifier
100
+ assert_equal nil, issue.repository
101
+ assert_equal "43", issue.number
102
+ end
103
+
104
+ should "not choke on case" do
105
+ text = "FIxEs #43"
106
+ parser = Ping::Parser.new(text)
107
+ issue = parser.issues.first
108
+
109
+ assert_equal "FIxEs", issue.qualifier
110
+ assert_equal nil, issue.repository
111
+ assert_equal "43", issue.number
112
+ end
113
+
114
+ should "require one space between qualifier and issue" do
115
+ text = "fixes #43"
116
+ parser = Ping::Parser.new(text)
117
+ issue = parser.issues.first
118
+
119
+ assert_equal nil, issue.qualifier
120
+ assert_equal nil, issue.repository
121
+ assert_equal "43", issue.number
122
+ end
123
+ end
18
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Reimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,10 +93,12 @@ files:
93
93
  - README.md
94
94
  - Rakefile
95
95
  - lib/ping.rb
96
+ - lib/ping/issue.rb
96
97
  - lib/ping/mention.rb
97
98
  - lib/ping/parser.rb
98
99
  - lib/ping/version.rb
99
100
  - ping.gemspec
101
+ - test/ping/issue_test.rb
100
102
  - test/ping/mention_test.rb
101
103
  - test/ping/parser_test.rb
102
104
  - test/test_helper.rb
@@ -125,6 +127,7 @@ signing_key:
125
127
  specification_version: 4
126
128
  summary: Parse @mentions and issue references
127
129
  test_files:
130
+ - test/ping/issue_test.rb
128
131
  - test/ping/mention_test.rb
129
132
  - test/ping/parser_test.rb
130
133
  - test/test_helper.rb