hizuke 0.0.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +12 -0
- data/lib/hizuke/parser.rb +75 -0
- data/lib/hizuke/version.rb +5 -0
- data/lib/hizuke.rb +25 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d343b5de1fbff044ba0cb10fdd1d9b23d5bd478abd7188583993e43f09e9ea1
|
4
|
+
data.tar.gz: d9a3b6746cf3da6dc60837a4e831bf2de0f510c69f62b8a11708293ff614d596
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77caa4db90322b19a37da5e82b875b88a00656675e17746962f4f305ca4365c7990855bbdd1241abfe5419efdd66da01f0a06caeaf5821514c07e9eaea54d0bf
|
7
|
+
data.tar.gz: d10748679690b857877d2bbcc33168499ee2f2459d37f7662b04b98570d266f09254bf96989fdb80b61aaf4a217a11517e57c79cb0623cde364b7b3699890b05
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [0.0.1] - 2025-04-12
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Initial release
|
12
|
+
- Basic date parsing functionality
|
13
|
+
- Support for "yesterday", "today", and "tomorrow" keywords
|
14
|
+
- Tests using Minitest
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hizuke (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.3)
|
10
|
+
json (2.10.2)
|
11
|
+
language_server-protocol (3.17.0.4)
|
12
|
+
lint_roller (1.1.0)
|
13
|
+
minitest (5.25.5)
|
14
|
+
parallel (1.26.3)
|
15
|
+
parser (3.3.7.4)
|
16
|
+
ast (~> 2.4.1)
|
17
|
+
racc
|
18
|
+
prism (1.4.0)
|
19
|
+
racc (1.8.1)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.2.1)
|
22
|
+
regexp_parser (2.10.0)
|
23
|
+
rubocop (1.75.2)
|
24
|
+
json (~> 2.3)
|
25
|
+
language_server-protocol (~> 3.17.0.2)
|
26
|
+
lint_roller (~> 1.1.0)
|
27
|
+
parallel (~> 1.10)
|
28
|
+
parser (>= 3.3.0.2)
|
29
|
+
rainbow (>= 2.2.2, < 4.0)
|
30
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
31
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
34
|
+
rubocop-ast (1.44.1)
|
35
|
+
parser (>= 3.3.7.2)
|
36
|
+
prism (~> 1.4)
|
37
|
+
ruby-progressbar (1.13.0)
|
38
|
+
unicode-display_width (3.1.4)
|
39
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
40
|
+
unicode-emoji (4.0.4)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
x86_64-darwin-24
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
hizuke!
|
48
|
+
minitest (~> 5.0)
|
49
|
+
rake (~> 13.0)
|
50
|
+
rubocop (~> 1.21)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.6.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Your Name
|
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,68 @@
|
|
1
|
+
# Hizuke
|
2
|
+
|
3
|
+
Hizuke is a simple Ruby gem that parses text containing date references like "yesterday", "today", and "tomorrow". It extracts the date and returns the clean text without the date reference.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'hizuke'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install hizuke
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'hizuke'
|
29
|
+
|
30
|
+
# Parse text with tomorrow's date
|
31
|
+
result = Hizuke.parse("wash car tomorrow")
|
32
|
+
puts result.text # => "wash car"
|
33
|
+
puts result.date # => <Date: 2023-04-01> (represents tomorrow's date)
|
34
|
+
|
35
|
+
# Parse text with today's date
|
36
|
+
result = Hizuke.parse("buy groceries today")
|
37
|
+
puts result.text # => "buy groceries"
|
38
|
+
puts result.date # => <Date: 2023-03-31> (represents today's date)
|
39
|
+
|
40
|
+
# Parse text with yesterday's date
|
41
|
+
result = Hizuke.parse("call mom yesterday")
|
42
|
+
puts result.text # => "call mom"
|
43
|
+
puts result.date # => <Date: 2023-03-30> (represents yesterday's date)
|
44
|
+
```
|
45
|
+
|
46
|
+
The parser is case-insensitive and can handle date references located anywhere in the text.
|
47
|
+
|
48
|
+
## Supported Date Keywords
|
49
|
+
|
50
|
+
Currently, the following English date keywords are supported:
|
51
|
+
|
52
|
+
- `yesterday` - returns yesterday's date
|
53
|
+
- `today` - returns today's date
|
54
|
+
- `tomorrow` - returns tomorrow's date
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
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).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/hizuke.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Hizuke
|
6
|
+
# Result object containing the clean text and extracted date
|
7
|
+
class Result
|
8
|
+
attr_reader :text, :date
|
9
|
+
|
10
|
+
def initialize(text, date)
|
11
|
+
@text = text
|
12
|
+
@date = date
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Parser class responsible for extracting dates from text
|
17
|
+
class Parser
|
18
|
+
# Date keywords mapping
|
19
|
+
DATE_KEYWORDS = {
|
20
|
+
"yesterday" => -1,
|
21
|
+
"today" => 0,
|
22
|
+
"tomorrow" => 1
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
# Parse text containing time references and extract both
|
26
|
+
# the clean text and the date.
|
27
|
+
#
|
28
|
+
# @param text [String] the text to parse
|
29
|
+
# @return [Hizuke::Result] the parsing result containing text and date
|
30
|
+
# @raise [Hizuke::ParseError] if no valid date reference is found
|
31
|
+
def self.parse(text)
|
32
|
+
new.parse(text)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Instance method to parse text
|
36
|
+
#
|
37
|
+
# @param text [String] the text to parse
|
38
|
+
# @return [Hizuke::Result] the parsing result containing text and date
|
39
|
+
# @raise [Hizuke::ParseError] if no valid date reference is found
|
40
|
+
def parse(text)
|
41
|
+
# Check if text is nil or empty
|
42
|
+
raise ParseError, "Input text cannot be nil or empty" if text.nil? || text.empty?
|
43
|
+
|
44
|
+
# Split the text into words
|
45
|
+
words = text.split
|
46
|
+
|
47
|
+
# Find the first date keyword
|
48
|
+
date_word_index = nil
|
49
|
+
date_offset = nil
|
50
|
+
|
51
|
+
words.each_with_index do |word, index|
|
52
|
+
clean_word = word.downcase.gsub(/[^a-z]/, '')
|
53
|
+
if DATE_KEYWORDS.key?(clean_word)
|
54
|
+
date_word_index = index
|
55
|
+
date_offset = DATE_KEYWORDS[clean_word]
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if date_word_index.nil?
|
61
|
+
raise ParseError, "No valid date reference found in '#{text}'"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Calculate the date based on the keyword
|
65
|
+
date = Date.today + date_offset
|
66
|
+
|
67
|
+
# Create the clean text by removing the date keyword
|
68
|
+
clean_words = words.dup
|
69
|
+
clean_words.delete_at(date_word_index)
|
70
|
+
clean_text = clean_words.join(" ").strip
|
71
|
+
|
72
|
+
Result.new(clean_text, date)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/hizuke.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "hizuke/version"
|
4
|
+
require_relative "hizuke/parser"
|
5
|
+
|
6
|
+
# Hizuke is a simple date parser that extracts dates from text
|
7
|
+
# containing time references like "yesterday", "today", and "tomorrow".
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# result = Hizuke.parse("wash car tomorrow")
|
11
|
+
# result.text # => "wash car"
|
12
|
+
# result.date # => <Date: 2023-04-01>
|
13
|
+
module Hizuke
|
14
|
+
# Parse text containing time references and extract both
|
15
|
+
# the clean text and the date.
|
16
|
+
#
|
17
|
+
# @param text [String] the text to parse
|
18
|
+
# @return [Hizuke::Result] the parsing result containing text and date
|
19
|
+
def self.parse(text)
|
20
|
+
Parser.parse(text)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Error raised when parsing fails
|
24
|
+
class ParseError < StandardError; end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hizuke
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juraj Maťaše
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
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: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.21'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.21'
|
55
|
+
description: Parse dates from text containing keywords like 'yesterday', 'today',
|
56
|
+
and 'tomorrow'
|
57
|
+
email:
|
58
|
+
- juraj@hey.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/hizuke.rb
|
70
|
+
- lib/hizuke/parser.rb
|
71
|
+
- lib/hizuke/version.rb
|
72
|
+
homepage: https://github.com/majur/hizuke
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
homepage_uri: https://github.com/majur/hizuke
|
77
|
+
source_code_uri: https://github.com/majur/hizuke
|
78
|
+
changelog_uri: https://github.com/majur/hizuke/blob/main/CHANGELOG.md
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.6.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: A simple date parser for text containing time references
|
98
|
+
test_files: []
|