ping 0.0.5 → 0.0.6

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: c17318b1d30362336aaf21ca89ab8cd282b9058d
4
- data.tar.gz: 605954bbe04c04076ccb996c9f3c4f4f0548c984
3
+ metadata.gz: 92094cfeedcd9adf5826698db686360f0b87f52b
4
+ data.tar.gz: f58ec2c03de3127eb407d684b0336f8819228efa
5
5
  SHA512:
6
- metadata.gz: 30b5f2cfcaa7d9daac0190094de884ba82f2212598c5d07bd6f1ba48a9c4edb3c36b8455803617309a980d659bd9b045a128e6a4548b27c9d5a621d69e762fd9
7
- data.tar.gz: 7e8b2b9fc768e4234bcb058b8c4f9f0f5ff4e3918a895de92e484d859a068458e12a636afe23d2eee31a271084852ef8d037f20076aa768491e6c059d2df8329
6
+ metadata.gz: 7bc19aa9205072e443d9ff61493e56e7e71e3175d031d013561566996e33ace7dc85621b5a9a4866e68abcad0ec6ea0fdae6098bea2f6e7f5dd17657785e2eff
7
+ data.tar.gz: 023de1fbd8ce729b94be5253e415ec36f022a34247f04ecf5a86bd35fcc29f361879ed1c405493544eb749c0f8f423d8a5a7afe14a1e0c5ae838f01a8954db9e
@@ -1,5 +1,6 @@
1
1
  require "ping/mention"
2
2
  require "ping/issue_reference"
3
+ require "ping/size"
3
4
 
4
5
  module Ping
5
6
  class Parser
@@ -20,5 +21,9 @@ module Ping
20
21
  def replace_issue_references(&block)
21
22
  Ping::IssueReference.replace(text, &block)
22
23
  end
24
+
25
+ def size
26
+ Ping::Size.extract(text)
27
+ end
23
28
  end
24
29
  end
@@ -0,0 +1,40 @@
1
+ module Ping
2
+ class Size
3
+ attr_accessor :points
4
+
5
+ Pattern = /
6
+ (?:^|\W) # beginning of string or non-word char
7
+ (?:size|points): # keyword
8
+ (\d+) # point value
9
+ (?=
10
+ \.+[ \t\W]| # dots followed by space or non-word character
11
+ \.+$| # dots at end of line
12
+ [^0-9a-zA-Z_.]| # non-word character except dot
13
+ $ # end of line
14
+ )
15
+ /ix
16
+
17
+ # See http://rubular.com/r/7u67dIwXuk
18
+
19
+ def self.extract(text)
20
+ matches = text.scan(Pattern)
21
+ matches.any? ? self.new(matches.last.first.to_i) : self.new(nil)
22
+ end
23
+
24
+ def initialize(points)
25
+ @points = points
26
+ end
27
+
28
+ def ==(other)
29
+ other.to_i == to_i
30
+ end
31
+
32
+ def to_i
33
+ points.to_i
34
+ end
35
+
36
+ def to_s
37
+ points.to_s
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Ping
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -325,4 +325,24 @@ class Ping::ParserTest < MiniTest::Test
325
325
  end
326
326
  end
327
327
  end
328
+
329
+ context "#size" do
330
+ should "extract the last point value" do
331
+ text = "Is this size:12 or size:14?"
332
+ parser = Ping::Parser.new(text)
333
+ assert_equal 14, parser.size.points
334
+ end
335
+
336
+ should "be indifferent to keyword casing" do
337
+ text = "SiZe:12"
338
+ parser = Ping::Parser.new(text)
339
+ assert_equal 12, parser.size.points
340
+ end
341
+
342
+ should "return nil if there is no size" do
343
+ text = "No size here"
344
+ parser = Ping::Parser.new(text)
345
+ assert_nil parser.size.points
346
+ end
347
+ end
328
348
  end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class Ping::SizeTest < MiniTest::Test
4
+ context "#==" do
5
+ should "compare with integers" do
6
+ size = Ping::Size.new(10)
7
+ assert size == 10
8
+ end
9
+
10
+ should "compare with nil" do
11
+ size = Ping::Size.new(10)
12
+ assert !(size == nil)
13
+
14
+ size = Ping::Size.new(0)
15
+ assert size == nil
16
+
17
+ size = Ping::Size.new(nil)
18
+ assert size == nil
19
+ end
20
+
21
+ should "compare with other sizes" do
22
+ size = Ping::Size.new(10)
23
+ assert Ping::Size.new(10) == size
24
+ assert !(Ping::Size.new(11) == size)
25
+ end
26
+ end
27
+
28
+ context "#to_s" do
29
+ should "return the points as a string" do
30
+ size = Ping::Size.new(10)
31
+ assert_equal "10", size.to_s
32
+ end
33
+ end
34
+
35
+ context "#to_i" do
36
+ should "return the integer points" do
37
+ size = Ping::Size.new(10)
38
+ assert_equal 10, size.to_i
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Reimer
@@ -96,11 +96,13 @@ files:
96
96
  - lib/ping/issue_reference.rb
97
97
  - lib/ping/mention.rb
98
98
  - lib/ping/parser.rb
99
+ - lib/ping/size.rb
99
100
  - lib/ping/version.rb
100
101
  - ping.gemspec
101
102
  - test/ping/issue_reference_test.rb
102
103
  - test/ping/mention_test.rb
103
104
  - test/ping/parser_test.rb
105
+ - test/ping/size_test.rb
104
106
  - test/test_helper.rb
105
107
  homepage: https://github.com/codetree/ping
106
108
  licenses:
@@ -130,5 +132,6 @@ test_files:
130
132
  - test/ping/issue_reference_test.rb
131
133
  - test/ping/mention_test.rb
132
134
  - test/ping/parser_test.rb
135
+ - test/ping/size_test.rb
133
136
  - test/test_helper.rb
134
137
  has_rdoc: