File: string_methods.rb

package info (click to toggle)
ruby-string-direction 1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212 kB
  • sloc: ruby: 657; makefile: 7; sh: 3
file content (35 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module StringDirection
  # Methods intended to be monkey patched to String through `String.include(StringDirection::StringMethods)`. This will allow stuff like `'English'.direction #=> 'ltr'`. All methods are delegated to {Detector} with `self` as string argument.
  module StringMethods
    # @see Detector#direction
    # @return [String]
    def direction
      string_direction_detector.direction(self)
    end

    # @see Detector#ltr?
    def ltr?
      string_direction_detector.ltr?(self)
    end

    # @see Detector#rtl?
    def rtl?
      string_direction_detector.rtl?(self)
    end

    # @see Detector#bidi?
    def bidi?
      string_direction_detector.bidi?(self)
    end

    private

    def string_direction_detector
      @string_direction_detector ||= StringDirection::Detector.new(*string_direction_strategies)
    end

    def string_direction_strategies
      StringDirection.configuration.string_methods_strategies
    end
  end
end