string-direction 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.
@@ -75,7 +75,8 @@ module StringDirection
75
75
  #
76
76
  # @return [Boolean] true if it containts ltr characters, false otherwise
77
77
  def has_ltr_characters?
78
- match(/[^#{StringDirection::join_scripts_for_regexp(StringDirection.rtl_scripts)}]/) ? true : false
78
+ # ignore unicode marks, punctuations, symbols, separator and other general categories
79
+ gsub(/[\p{M}\p{P}\p{S}\p{Z}\p{C}]/, '').match(/[^#{StringDirection::join_scripts_for_regexp(StringDirection.rtl_scripts)}]/) ? true : false
79
80
  end
80
81
 
81
82
  class << self
@@ -50,6 +50,17 @@ describe String do
50
50
  StringDirection.rtl_scripts.delete new_rtl_script if StringDirection.rtl_scripts.include? new_rtl_script
51
51
  StringDirection.rtl_scripts << old_rtl_script unless StringDirection.rtl_scripts.include? old_rtl_script
52
52
  end
53
+ context "when special characters are present" do
54
+ it "should ignore special characters for the direction detection" do
55
+ mark = "\u0903"
56
+ punctuation = "_"
57
+ symbol = "€"
58
+ separator = " "
59
+ other = "\u0005"
60
+ string = arabic+mark+punctuation+symbol+separator+other
61
+ string.direction.should eql 'rtl'
62
+ end
63
+ end
53
64
  end
54
65
  end
55
66
  describe "#is_ltr?" do
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'string-direction'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.summary = 'Automatic detection of text direction (ltr, rtl or bidi) for strings'
5
5
  s.description = 'https://github.com/laMarciana/string-direction/'
6
6
  s.license = 'GPL3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-direction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: