twitter-text 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,20 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Twitter
4
- class WeightedRange
5
- attr_reader :start, :end, :weight
4
+ module TwitterText
5
+ class WeightedRange
6
+ attr_reader :start, :end, :weight
6
7
 
7
- def initialize(range = {})
8
- raise ArgumentError.new("Invalid range") unless [:start, :end, :weight].all? { |key| range.key?(key) && range[key].is_a?(Integer) }
9
- @start = range[:start]
10
- @end = range[:end]
11
- @weight = range[:weight]
12
- end
8
+ def initialize(range = {})
9
+ raise ArgumentError.new("Invalid range") unless [:start, :end, :weight].all? { |key| range.key?(key) && range[key].is_a?(Integer) }
10
+ @start = range[:start]
11
+ @end = range[:end]
12
+ @weight = range[:weight]
13
+ end
13
14
 
14
- def contains?(code_point)
15
- code_point >= @start && code_point <= @end
15
+ def contains?(code_point)
16
+ code_point >= @start && code_point <= @end
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -2,10 +2,10 @@
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
4
  class TestAutolink
5
- include Twitter::Autolink
5
+ include Twitter::TwitterText::Autolink
6
6
  end
7
7
 
8
- describe Twitter::Autolink do
8
+ describe Twitter::TwitterText::Autolink do
9
9
  def original_text; end
10
10
  def url; end
11
11
 
@@ -1,34 +1,34 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
- describe Twitter::Configuration do
4
+ describe Twitter::TwitterText::Configuration do
5
5
  context "configuration" do
6
6
  context "with invalid data" do
7
7
  it "should raise an exception" do
8
- invalid_hash = Twitter::Configuration.parse_string("{\"version\":2,\"maxWeightedTweetLength\":280,\"scale\":100,\"defaultWeight\":200,\"transformedURLLength\":23,\"ranges\":[{\"start\":0,\"end\":true,\"weight\":false},{\"start\":8192,\"end\":8205,\"weight\":100},{\"start\":8208,\"end\":8223,\"weight\":100},{\"start\":8242,\"end\":8247,\"weight\":100}]}")
9
- expect { Twitter::Configuration.new(invalid_hash) }.to raise_error(ArgumentError)
8
+ invalid_hash = Twitter::TwitterText::Configuration.parse_string("{\"version\":2,\"maxWeightedTweetLength\":280,\"scale\":100,\"defaultWeight\":200,\"transformedURLLength\":23,\"ranges\":[{\"start\":0,\"end\":true,\"weight\":false},{\"start\":8192,\"end\":8205,\"weight\":100},{\"start\":8208,\"end\":8223,\"weight\":100},{\"start\":8242,\"end\":8247,\"weight\":100}]}")
9
+ expect { Twitter::TwitterText::Configuration.new(invalid_hash) }.to raise_error(ArgumentError)
10
10
  end
11
11
  end
12
12
 
13
13
  context "with defaults" do
14
14
  before do
15
- Twitter::Configuration.default_configuration = Twitter::Configuration.configuration_from_file(Twitter::Configuration::CONFIG_V2)
15
+ Twitter::TwitterText::Configuration.default_configuration = Twitter::TwitterText::Configuration.configuration_from_file(Twitter::TwitterText::Configuration::CONFIG_V2)
16
16
  end
17
17
 
18
18
  it "should define version constants" do
19
- expect(Twitter::Configuration.const_defined?(:CONFIG_V1)).to be true
20
- expect(Twitter::Configuration.const_defined?(:CONFIG_V2)).to be true
19
+ expect(Twitter::TwitterText::Configuration.const_defined?(:CONFIG_V1)).to be true
20
+ expect(Twitter::TwitterText::Configuration.const_defined?(:CONFIG_V2)).to be true
21
21
  end
22
22
 
23
23
  it "should define a default configuration" do
24
- expect(Twitter::Configuration.default_configuration).to_not be_nil
25
- expect(Twitter::Configuration.default_configuration.version).to eq(2)
24
+ expect(Twitter::TwitterText::Configuration.default_configuration).to_not be_nil
25
+ expect(Twitter::TwitterText::Configuration.default_configuration.version).to eq(2)
26
26
  end
27
27
  end
28
28
 
29
29
  context "with v1 configuration" do
30
30
  before do
31
- @config = Twitter::Configuration.configuration_from_file(Twitter::Configuration::CONFIG_V1)
31
+ @config = Twitter::TwitterText::Configuration.configuration_from_file(Twitter::TwitterText::Configuration::CONFIG_V1)
32
32
  end
33
33
 
34
34
  it "should have a version" do
@@ -54,7 +54,7 @@ describe Twitter::Configuration do
54
54
 
55
55
  context "with v2 configuration" do
56
56
  before do
57
- @config = Twitter::Configuration.configuration_from_file(Twitter::Configuration::CONFIG_V2)
57
+ @config = Twitter::TwitterText::Configuration.configuration_from_file(Twitter::TwitterText::Configuration::CONFIG_V2)
58
58
  end
59
59
 
60
60
  it "should have a version" do
@@ -80,7 +80,7 @@ describe Twitter::Configuration do
80
80
  it "should have a configured range" do
81
81
  expect(@config.ranges).to be_kind_of(Array)
82
82
  expect(@config.ranges.count).to be > 0
83
- expect(@config.ranges[0]).to be_kind_of(Twitter::WeightedRange)
83
+ expect(@config.ranges[0]).to be_kind_of(Twitter::TwitterText::WeightedRange)
84
84
  weighted_range = @config.ranges[0]
85
85
  expect(weighted_range.start).to be_kind_of(Integer)
86
86
  expect(weighted_range.end).to be_kind_of(Integer)
@@ -2,10 +2,10 @@
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
4
  class TestExtractor
5
- include Twitter::Extractor
5
+ include Twitter::TwitterText::Extractor
6
6
  end
7
7
 
8
- describe Twitter::Extractor do
8
+ describe Twitter::TwitterText::Extractor do
9
9
  before do
10
10
  @extractor = TestExtractor.new
11
11
  end
@@ -241,7 +241,7 @@ describe Twitter::Extractor do
241
241
  it "does not consider a long URL with protocol to be valid" do
242
242
  # maximum length of domain label is 32 chars.
243
243
  url = ("a" * 31) + "."
244
- url *= (Twitter::Extractor::MAX_URL_LENGTH / 32)
244
+ url *= (Twitter::TwitterText::Extractor::MAX_URL_LENGTH / 32)
245
245
  url = "https://" + url + "com" # longer than 4096 (MAX_URL_LENGTH) chars
246
246
  expect(@extractor.is_valid_domain(url.length, url, true)).to be false
247
247
  end
@@ -249,7 +249,7 @@ describe Twitter::Extractor do
249
249
  it "does not consider a long URL without protocol to be valid" do
250
250
  # maximum length of domain label is 32 chars.
251
251
  url = ("a" * 31) + "."
252
- url *= ((Twitter::Extractor::MAX_URL_LENGTH / 32) - 1)
252
+ url *= ((Twitter::TwitterText::Extractor::MAX_URL_LENGTH / 32) - 1)
253
253
  url = url + "com" # shorter than 4096 (MAX_URL_LENGTH) chars
254
254
  expect(@extractor.is_valid_domain(url.length, url, false)).to be true
255
255
  url = ("a" * (31 - "https://".length)) + "." + url
@@ -309,11 +309,11 @@ describe Twitter::Extractor do
309
309
  end
310
310
 
311
311
  it "should not allow the multiplication character" do
312
- expect(@extractor.extract_hashtags("#pre#{Twitter::Unicode::U00D7}post")).to be == ["pre"]
312
+ expect(@extractor.extract_hashtags("#pre#{Twitter::TwitterText::Unicode::U00D7}post")).to be == ["pre"]
313
313
  end
314
314
 
315
315
  it "should not allow the division character" do
316
- expect(@extractor.extract_hashtags("#pre#{Twitter::Unicode::U00F7}post")).to be == ["pre"]
316
+ expect(@extractor.extract_hashtags("#pre#{Twitter::TwitterText::Unicode::U00F7}post")).to be == ["pre"]
317
317
  end
318
318
  end
319
319
 
@@ -2,10 +2,10 @@
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
4
  class TestHitHighlighter
5
- include Twitter::HitHighlighter
5
+ include Twitter::TwitterText::HitHighlighter
6
6
  end
7
7
 
8
- describe Twitter::HitHighlighter do
8
+ describe Twitter::TwitterText::HitHighlighter do
9
9
  describe "highlight" do
10
10
  before do
11
11
  @highlighter = TestHitHighlighter.new
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
- describe "Twitter::Regex regular expressions" do
4
+ describe "Twitter::TwitterText::Regex regular expressions" do
5
5
  describe "matching URLS" do
6
6
  TestUrls::VALID.each do |url|
7
7
  it "should match the URL #{url}" do
@@ -25,13 +25,13 @@ describe "Twitter::Regex regular expressions" do
25
25
  it "should match if less than 25 characters" do
26
26
  name = "Shuffleboard Community"
27
27
  expect(name.length).to be < 25
28
- expect(name).to match(Twitter::Regex::REGEXEN[:list_name])
28
+ expect(name).to match(Twitter::TwitterText::Regex::REGEXEN[:list_name])
29
29
  end
30
30
 
31
31
  it "should not match if greater than 25 characters" do
32
32
  name = "Most Glorious Shady Meadows Shuffleboard Community"
33
33
  expect(name.length).to be > 25
34
- expect(name).to match(Twitter::Regex[:list_name])
34
+ expect(name).to match(Twitter::TwitterText::Regex[:list_name])
35
35
  end
36
36
 
37
37
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
- describe Twitter::Rewriter do
4
+ describe Twitter::TwitterText::Rewriter do
5
5
  def original_text; end
6
6
  def url; end
7
7
 
@@ -19,7 +19,7 @@ describe Twitter::Rewriter do
19
19
 
20
20
  describe "rewrite usernames" do #{{{
21
21
  before do
22
- @rewritten_text = Twitter::Rewriter.rewrite_usernames_or_lists(original_text, &method(:block))
22
+ @rewritten_text = Twitter::TwitterText::Rewriter.rewrite_usernames_or_lists(original_text, &method(:block))
23
23
  end
24
24
 
25
25
  context "username preceded by a space" do
@@ -120,7 +120,7 @@ describe Twitter::Rewriter do
120
120
 
121
121
  describe "rewrite lists" do #{{{
122
122
  before do
123
- @rewritten_text = Twitter::Rewriter.rewrite_usernames_or_lists(original_text, &method(:block))
123
+ @rewritten_text = Twitter::TwitterText::Rewriter.rewrite_usernames_or_lists(original_text, &method(:block))
124
124
  end
125
125
 
126
126
  context "slug preceded by a space" do
@@ -201,7 +201,7 @@ describe Twitter::Rewriter do
201
201
 
202
202
  describe "rewrite hashtags" do #{{{
203
203
  before do
204
- @rewritten_text = Twitter::Rewriter.rewrite_hashtags(original_text, &method(:block))
204
+ @rewritten_text = Twitter::TwitterText::Rewriter.rewrite_hashtags(original_text, &method(:block))
205
205
  end
206
206
 
207
207
  context "with an all numeric hashtag" do
@@ -338,7 +338,7 @@ describe Twitter::Rewriter do
338
338
  def url; "http://www.google.com"; end
339
339
 
340
340
  before do
341
- @rewritten_text = Twitter::Rewriter.rewrite_urls(original_text, &method(:block))
341
+ @rewritten_text = Twitter::TwitterText::Rewriter.rewrite_urls(original_text, &method(:block))
342
342
  end
343
343
 
344
344
  context "when embedded in plain text" do
@@ -452,7 +452,7 @@ describe Twitter::Rewriter do
452
452
  context "with a URL ending in allowed punctuation" do
453
453
  it "does not consume ending punctuation" do
454
454
  %w| ? ! , . : ; ] ) } = \ ' |.each do |char|
455
- expect(Twitter::Rewriter.rewrite_urls("#{url}#{char}") do |url|
455
+ expect(Twitter::TwitterText::Rewriter.rewrite_urls("#{url}#{char}") do |url|
456
456
  expect(url).to be == url
457
457
  "[rewritten]"
458
458
  end).to be == "[rewritten]#{char}"
@@ -463,7 +463,7 @@ describe Twitter::Rewriter do
463
463
  context "with a URL preceded in forbidden characters" do
464
464
  it "should be rewritten" do
465
465
  %w| \ ' / ! = |.each do |char|
466
- expect(Twitter::Rewriter.rewrite_urls("#{char}#{url}") do |url|
466
+ expect(Twitter::TwitterText::Rewriter.rewrite_urls("#{char}#{url}") do |url|
467
467
  "[rewritten]" # should not be called here.
468
468
  end).to be == "#{char}[rewritten]"
469
469
  end
@@ -24,13 +24,13 @@ end
24
24
 
25
25
  RSpec::Matchers.define :match_autolink_expression do
26
26
  match do |string|
27
- !Twitter::Extractor.extract_urls(string).empty?
27
+ !Twitter::TwitterText::Extractor.extract_urls(string).empty?
28
28
  end
29
29
  end
30
30
 
31
31
  RSpec::Matchers.define :match_autolink_expression_in do |text|
32
32
  match do |url|
33
- @match_data = Twitter::Regex[:valid_url].match(text)
33
+ @match_data = Twitter::TwitterText::Regex[:valid_url].match(text)
34
34
  @match_data && @match_data.to_s.strip == url
35
35
  end
36
36
 
@@ -1,31 +1,31 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
- describe Twitter::Unicode do
4
+ describe Twitter::TwitterText::Unicode do
5
5
 
6
6
  it "should lazy-init constants" do
7
- expect(Twitter::Unicode.const_defined?(:UFEB6)).to eq(false)
8
- expect(Twitter::Unicode::UFEB6).to_not be_nil
9
- expect(Twitter::Unicode::UFEB6).to be_kind_of(String)
10
- expect(Twitter::Unicode.const_defined?(:UFEB6)).to eq(true)
7
+ expect(Twitter::TwitterText::Unicode.const_defined?(:UFEB6)).to eq(false)
8
+ expect(Twitter::TwitterText::Unicode::UFEB6).to_not be_nil
9
+ expect(Twitter::TwitterText::Unicode::UFEB6).to be_kind_of(String)
10
+ expect(Twitter::TwitterText::Unicode.const_defined?(:UFEB6)).to eq(true)
11
11
  end
12
12
 
13
13
  it "should return corresponding character" do
14
- expect(Twitter::Unicode::UFEB6).to be == [0xfeb6].pack('U')
14
+ expect(Twitter::TwitterText::Unicode::UFEB6).to be == [0xfeb6].pack('U')
15
15
  end
16
16
 
17
17
  it "should allow lowercase notation" do
18
- expect(Twitter::Unicode::Ufeb6).to be == Twitter::Unicode::UFEB6
19
- expect(Twitter::Unicode::Ufeb6).to be === Twitter::Unicode::UFEB6
18
+ expect(Twitter::TwitterText::Unicode::Ufeb6).to be == Twitter::TwitterText::Unicode::UFEB6
19
+ expect(Twitter::TwitterText::Unicode::Ufeb6).to be === Twitter::TwitterText::Unicode::UFEB6
20
20
  end
21
21
 
22
22
  it "should allow underscore notation" do
23
- expect(Twitter::Unicode::U_FEB6).to be == Twitter::Unicode::UFEB6
24
- expect(Twitter::Unicode::U_FEB6).to be === Twitter::Unicode::UFEB6
23
+ expect(Twitter::TwitterText::Unicode::U_FEB6).to be == Twitter::TwitterText::Unicode::UFEB6
24
+ expect(Twitter::TwitterText::Unicode::U_FEB6).to be === Twitter::TwitterText::Unicode::UFEB6
25
25
  end
26
26
 
27
27
  it "should raise on invalid codepoints" do
28
- expect(lambda { Twitter::Unicode::FFFFFF }).to raise_error(NameError)
28
+ expect(lambda { Twitter::TwitterText::Unicode::FFFFFF }).to raise_error(NameError)
29
29
  end
30
30
 
31
31
  end
@@ -2,18 +2,18 @@
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
4
  class TestValidation
5
- include Twitter::Validation
5
+ include Twitter::TwitterText::Validation
6
6
  end
7
7
 
8
- describe Twitter::Validation do
8
+ describe Twitter::TwitterText::Validation do
9
9
 
10
10
  it "should disallow invalid BOM character" do
11
- expect(TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFFFE}")).to be == :invalid_characters
12
- expect(TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFEFF}")).to be == :invalid_characters
11
+ expect(TestValidation.new.tweet_invalid?("Bom:#{Twitter::TwitterText::Unicode::UFFFE}")).to be == :invalid_characters
12
+ expect(TestValidation.new.tweet_invalid?("Bom:#{Twitter::TwitterText::Unicode::UFEFF}")).to be == :invalid_characters
13
13
  end
14
14
 
15
15
  it "should disallow invalid U+FFFF character" do
16
- expect(TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFFFF}")).to be == :invalid_characters
16
+ expect(TestValidation.new.tweet_invalid?("Bom:#{Twitter::TwitterText::Unicode::UFFFF}")).to be == :invalid_characters
17
17
  end
18
18
 
19
19
  it "should disallow direction change characters" do
@@ -42,7 +42,7 @@ describe Twitter::Validation do
42
42
 
43
43
  context "when returning results" do
44
44
  it "should properly create new fully-populated results from arguments" do
45
- results = Twitter::Validation::ParseResults.new(weighted_length: 26, permillage: 92, valid: true, display_range_start: 0, display_range_end: 16, valid_range_start: 0, valid_range_end:16)
45
+ results = Twitter::TwitterText::Validation::ParseResults.new(weighted_length: 26, permillage: 92, valid: true, display_range_start: 0, display_range_end: 16, valid_range_start: 0, valid_range_end:16)
46
46
  expect(results).to_not be nil
47
47
  expect(results[:weighted_length]).to eq(26)
48
48
  expect(results[:permillage]).to eq(92)
@@ -54,7 +54,7 @@ describe Twitter::Validation do
54
54
  end
55
55
 
56
56
  it "should properly create empty results" do
57
- results = Twitter::Validation::ParseResults.empty()
57
+ results = Twitter::TwitterText::Validation::ParseResults.empty()
58
58
  expect(results[:weighted_length]).to eq(0)
59
59
  expect(results[:permillage]).to eq(0)
60
60
  expect(results[:valid]).to be true
@@ -15,10 +15,10 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
15
15
  require 'twitter-text'
16
16
 
17
17
  class ConformanceTest < Test::Unit::TestCase
18
- include Twitter::Extractor
19
- include Twitter::Autolink
20
- include Twitter::HitHighlighter
21
- include Twitter::Validation
18
+ include Twitter::TwitterText::Extractor
19
+ include Twitter::TwitterText::Autolink
20
+ include Twitter::TwitterText::HitHighlighter
21
+ include Twitter::TwitterText::Validation
22
22
 
23
23
  private
24
24
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "twitter-text"
5
- s.version = "2.0.2"
5
+ s.version = "2.1.0"
6
6
  s.authors = ["David LaMacchia", "Sudheer Guntupalli", "Kaushik Lakshmikanth", "Jose Antonio Marquez Russo", "Lee Adams",
7
7
  "Yoshimasa Niwa"]
8
8
  s.email = ["opensource@twitter.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David LaMacchia
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-12-19 00:00:00.000000000 Z
16
+ date: 2017-12-21 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: pry
@@ -166,6 +166,7 @@ files:
166
166
  - ".gitignore"
167
167
  - ".gitmodules"
168
168
  - ".rspec"
169
+ - CHANGELOG.md
169
170
  - Gemfile
170
171
  - LICENSE
171
172
  - README.md