parselly 0.1.0

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/MIT +21 -0
  3. data/README.md +30 -0
  4. data/Rakefile +11 -0
  5. data/lib/parselly.rb +48 -0
  6. metadata +51 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c687b7a170537d06d5a7fa1bbcc374c0826b73c167917cf42a44edd7eea9928
4
+ data.tar.gz: 2dcce5b4d335f893ad3a30587e264c1c0dd6d0177d2f1a4790b23096b8f0a257
5
+ SHA512:
6
+ metadata.gz: 12982469258ee3f3ce04343948d6a605cbcdb91c87e1af25b3dd2233c1cb29512e89716dcf765c6680909096e78f23a40041ff5b25d753c058b2e34afac82fed
7
+ data.tar.gz: 7cc9778bd541fc4a4c160d407ce3ee85399efadd7532220053b6e5700e9ae962e95657856cb1ba6c4a12cb955a931446b9dd98918e8c4d39455f0ce2b0b0af8c
data/MIT ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Yudai Takada
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.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Parselly
2
+
3
+ Parselly is a module providing a simple way to parse and extract data from a css selector.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+ ```ruby
9
+ gem 'parselly'
10
+ ```
11
+
12
+ And then execute:
13
+ ```bash
14
+ bundle install
15
+ ```
16
+
17
+ Or install it yourself as:
18
+ ```bash
19
+ gem install parselly
20
+ ```
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ydah/parselly.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test/lib"
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ end
10
+
11
+ task default: :test
data/lib/parselly.rb ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'strscan'
4
+
5
+ class Parselly
6
+ VERSION = "0.1.0"
7
+
8
+ def self.sanitize(selector)
9
+ scanner = StringScanner.new(selector)
10
+ result = +''
11
+
12
+ # Special case: if the selector is of length 1 and
13
+ # the first character is `-`
14
+ if selector.length == 1 && scanner.peek(1) == '-'
15
+ return "\\#{selector}"
16
+ end
17
+
18
+ until scanner.eos?
19
+ # NULL character (U+0000)
20
+ if scanner.scan(/\0/)
21
+ result << "\uFFFD"
22
+ # Control characters (U+0001 to U+001F, U+007F)
23
+ elsif scanner.scan(/[\x01-\x1F\x7F]/)
24
+ result << escaped_hex(scanner.matched)
25
+ # First character is a digit (U+0030 to U+0039)
26
+ elsif scanner.pos.zero? && scanner.scan(/\d/)
27
+ result << escaped_hex(scanner.matched)
28
+ # Second character is a digit and first is `-`
29
+ elsif scanner.pos == 1 && scanner.scan(/\d/) &&
30
+ scanner.pre_match == '-'
31
+ result << escaped_hex(scanner.matched)
32
+ # Alphanumeric characters, `-`, `_`
33
+ elsif scanner.scan(/[a-zA-Z0-9\-_]/)
34
+ result << scanner.matched
35
+ # Any other characters, escape them
36
+ elsif scanner.scan(/./)
37
+ result << "\\#{scanner.matched}"
38
+ end
39
+ end
40
+
41
+ result
42
+ end
43
+
44
+ def self.escaped_hex(char)
45
+ "\\#{char.ord.to_s(16)} "
46
+ end
47
+ private_class_method :escaped_hex
48
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parselly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yudai Takada
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-01-24 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Parselly is a pure Ruby CSS selector parser. Provides a simple and easy-to-use
13
+ API for parsing CSS selectors.
14
+ email:
15
+ - t.yudai92@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT
21
+ - README.md
22
+ - Rakefile
23
+ - lib/parselly.rb
24
+ homepage: https://github.com/ydah/parselly
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ homepage_uri: https://github.com/ydah/parselly
29
+ source_code_uri: https://github.com/ydah/parselly
30
+ documentation_uri: https://github.com/ydah/parselly
31
+ changelog_uri: https://github.com/ydah/parselly/releases
32
+ bug_tracker_uri: https://github.com/ydah/parselly/issues
33
+ rubygems_mfa_required: 'true'
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.7.0.dev
49
+ specification_version: 4
50
+ summary: Pure Ruby CSS selector parser.
51
+ test_files: []