turkish_regexps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4fc759ade02aabeb34dc4a950f58323f2c8a8b4dbbc3e5376e02a89566873866
4
+ data.tar.gz: 5b9b28232aab2db84c98854f7d2a081f32aced877418e04395be98ba5cfaac61
5
+ SHA512:
6
+ metadata.gz: 1ffc78874714bfa6977f5dc771df8f93524de20e4eb54f4daa048a4c7fd27b07806dd2c40c85f7693d75e8baf43f0eb3b427e92e292fb43f39fd5f82ca680701
7
+ data.tar.gz: d374774574b0c855d1a60aed9a6f7c91913e35be2e4235e4c14f38ad69ea349b28cc25c1c84e9acc97589768809243eaa5acb3f6ad67a92968c53ae5ed8bf9d4
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+ Layout/DotPosition:
5
+ EnforcedStyle: leading
6
+ Enabled: true
7
+ Style/StringLiterals:
8
+ EnforcedStyle: single_quotes
9
+ Style/AsciiComments:
10
+ Enabled: false
11
+ Style/FrozenStringLiteralComment:
12
+ Exclude:
13
+ - 'bin/console'
14
+ - 'Rakefile'
15
+ Metrics/BlockLength:
16
+ ExcludedMethods:
17
+ - 'describe'
18
+ - 'context'
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+ ## [Version 0.1.0](https://github.com/sbagdat/turkish_regexps/releases/tag/v0.1.0) (2020-11-25)
3
+ ### Added
4
+ - Capability to create regexp character classes containing turkish characters [`a057bd7`](https://github.com/sbagdat/turkish_regexps/commit/a057bd7)
5
+ - Capability to create meta characters containing turkish characters [`a057bd7`](https://github.com/sbagdat/turkish_regexps/commit/a057bd7)
6
+ - Creating turkish supported regexps with TrRegexp#new [`a057bd7`](https://github.com/sbagdat/turkish_regexps/CHANGELOG.md/commit/a057bd7)
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sbagdat@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+ ruby '~> 2.7.0'
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ turkish_regexps (0.1.0)
5
+ turkish_ranges (~> 0.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.4.4)
11
+ rake (13.0.1)
12
+ rspec (3.10.0)
13
+ rspec-core (~> 3.10.0)
14
+ rspec-expectations (~> 3.10.0)
15
+ rspec-mocks (~> 3.10.0)
16
+ rspec-core (3.10.0)
17
+ rspec-support (~> 3.10.0)
18
+ rspec-expectations (3.10.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.10.0)
21
+ rspec-mocks (3.10.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-support (3.10.0)
25
+ turkish_ranges (0.1.2)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ rake (~> 13.0)
32
+ rspec (~> 3.10)
33
+ turkish_ranges (~> 0.1)
34
+ turkish_regexps!
35
+
36
+ RUBY VERSION
37
+ ruby 2.7.0p0
38
+
39
+ BUNDLED WITH
40
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Sıtkı Bağdat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # TurkishRanges
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/turkish_regexps.svg)](https://badge.fury.io/rb/turkish_regexps)
4
+ [![Build Status](https://travis-ci.org/sbagdat/turkish_regexps.svg?branch=main)](https://travis-ci.org/sbagdat/turkish_regexps)
5
+ [![Code Climate](https://codeclimate.com/github/sbagdat/turkish_regexps/badges/gpa.svg)](https://codeclimate.com/github/sbagdat/turkish_regexps)
6
+
7
+ Regular expressions meet Turkish language.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'turkish_regexps'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install turkish_regexps
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'turkish_regexps'
29
+
30
+ include TurkishRegexps
31
+
32
+ # Creating new regexps
33
+ TrRegexp.new(/[ç-ş]/i)
34
+
35
+ # Translating character classes
36
+ TrRegexp.new(/[ç-ö]/).translate # /[çdefgğhıijklmnoö]/
37
+ TrRegexp.new(/[A-Z]/).translate # /[ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ]/
38
+ TrRegexp.new(/[Ç-Ş#!$ç-ş]/).translate # /[ÇDEFGĞHIİJKLMNOÖPQRSŞ#!$çdefgğhıijklmnoöpqrsş]/
39
+
40
+ # Translating meta characters
41
+ re = TrRegexp.new(/\w+/).translate
42
+ Regexp.compile(re).match('ABCÇDEFGĞHIİJKLMNOÖPQRSabcçdeğiş')[0] # 'ABCÇDEFGĞHIİJKLMNOÖPQRSabcçdeğiş'
43
+
44
+ re = TrRegexp.new(/\W+/).translate
45
+ Regexp.compile(re).match('ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ.+%')[0] # '.+%'
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/turkish_regexps. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/turkish_regexps/blob/master/CODE_OF_CONDUCT.md).
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the TurkishRanges project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/turkish_regexps/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :cops do
9
+ sh 'rubocop'
10
+ puts '-' * 50
11
+ sh 'reek'
12
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'turkish_regexps'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'turkish_ranges'
4
+ require 'turkish_regexps/version'
5
+ require 'turkish_regexps/tr_regexp'
6
+
7
+ module TurkishRegexps
8
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurkishRegexps
4
+ # Let your regexps to speak in Turkish
5
+ class TrRegexp
6
+ # A new instance of TrRegexp
7
+ #
8
+ # @param [Regexp] pattern
9
+ # @return [TrRegexp]
10
+ def initialize(pattern)
11
+ @source = pattern.source
12
+ @options = pattern.options
13
+ @casefold = pattern.casefold?
14
+ end
15
+
16
+ # Translate regexps into Turkish supported version
17
+ #
18
+ # @return [Regexp]
19
+ def translate
20
+ translate_matches
21
+ add_meta_charset
22
+ set_encoding
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :source, :options, :casefold
28
+
29
+ # Find character class inside regexp, then change them with an extended version
30
+ #
31
+ # @return [NilClass]
32
+ def translate_matches
33
+ char_class_re = /(.)-(.)/.freeze
34
+ source.gsub!(char_class_re) { translate_range(*_1.split('-')) }
35
+ nil
36
+ end
37
+
38
+ # Translate range of character class
39
+ #
40
+ # @param [String] first
41
+ # @param [String] last
42
+ # @return [String]
43
+ def translate_range(first, last)
44
+ (TurkishRanges::TrText.new(first)..TurkishRanges::TrText.new(last)).to_a.join \
45
+ complement_range(first, last)
46
+ end
47
+
48
+ # Translate complement range of character class if regexp is case-insensitive
49
+ #
50
+ # @param [String] first
51
+ # @param [String] last
52
+ # @return [String]
53
+ def complement_range(first, last)
54
+ casefold ? (TurkishRanges::TrText.new(first.swapcase)..TurkishRanges::TrText.new(last.swapcase)).to_a.join : ''
55
+ end
56
+
57
+ # Expand meta characters to latin
58
+ #
59
+ # @return [NilClass]
60
+ def add_meta_charset
61
+ meta = { '\w' => '[\p{Latin}\d_]', '\W' => '[^\p{Latin}\d_]' }.freeze
62
+ meta.each { source.gsub!(_1, _2) }
63
+ nil
64
+ end
65
+
66
+ # Creates the last form of translated regexp, ready to use
67
+ #
68
+ # @return [Regexp]
69
+ def set_encoding
70
+ Regexp.new(source.force_encoding('UTF-8'), Regexp::FIXEDENCODING | options)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurkishRegexps
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/turkish_regexps/version'
4
+
5
+ lib = File.expand_path('lib', __dir__)
6
+ $LOAD_PATH.prepend(lib) unless $LOAD_PATH.include?(lib)
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'turkish_regexps'
10
+ spec.version = TurkishRegexps::VERSION
11
+ spec.authors = ['Sıtkı Bağdat']
12
+ spec.email = ['sbagdat@gmail.com']
13
+ spec.summary = 'Let your regular expressions to speak in Turkish '
14
+ spec.description = 'Regular expression meet Turkish language. You can use ' \
15
+ 'character classes and meta characters in your regexps ' \
16
+ 'without worrying about Turkish support.'
17
+ spec.homepage = 'https://github.com/sbagdat/turkish_regexps'
18
+ spec.license = 'MIT'
19
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
24
+
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'bin'
29
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_runtime_dependency 'turkish_ranges', '~> 0.1'
33
+
34
+ spec.add_development_dependency 'rake', '~> 13.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.10'
36
+ spec.add_development_dependency 'turkish_ranges', '~> 0.1'
37
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turkish_regexps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sıtkı Bağdat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: turkish_ranges
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turkish_ranges
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ description: Regular expression meet Turkish language. You can use character classes
70
+ and meta characters in your regexps without worrying about Turkish support.
71
+ email:
72
+ - sbagdat@gmail.com
73
+ executables:
74
+ - console
75
+ - setup
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".rubocop.yml"
82
+ - ".travis.yml"
83
+ - CHANGELOG.md
84
+ - CODE_OF_CONDUCT.md
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/setup
92
+ - lib/turkish_regexps.rb
93
+ - lib/turkish_regexps/tr_regexp.rb
94
+ - lib/turkish_regexps/version.rb
95
+ - turkish_regexps.gemspec
96
+ homepage: https://github.com/sbagdat/turkish_regexps
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://github.com/sbagdat/turkish_regexps
101
+ source_code_uri: https://github.com/sbagdat/turkish_regexps
102
+ changelog_uri: https://github.com/sbagdat/turkish_regexps/blob/main/CHANGELOG.md
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.7.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.1.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Let your regular expressions to speak in Turkish
122
+ test_files: []