hizuke 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d343b5de1fbff044ba0cb10fdd1d9b23d5bd478abd7188583993e43f09e9ea1
4
- data.tar.gz: d9a3b6746cf3da6dc60837a4e831bf2de0f510c69f62b8a11708293ff614d596
3
+ metadata.gz: 064d7574f7151fdf7695b789dd4812f38c6becb6226b7bda807d0339dc0fc8e1
4
+ data.tar.gz: 48c23cc779ae564bc3625176f7af74ebb2c0b33a7f4f67cea5098851c35de2e0
5
5
  SHA512:
6
- metadata.gz: 77caa4db90322b19a37da5e82b875b88a00656675e17746962f4f305ca4365c7990855bbdd1241abfe5419efdd66da01f0a06caeaf5821514c07e9eaea54d0bf
7
- data.tar.gz: d10748679690b857877d2bbcc33168499ee2f2459d37f7662b04b98570d266f09254bf96989fdb80b61aaf4a217a11517e57c79cb0623cde364b7b3699890b05
6
+ metadata.gz: 22380b935099c93601a9ac54837e4378935037d653e5ee557c1fc7cdd31098245fbb3bc4c3e5c6623c431fdb9f54138fb3445dbe18e9197721caf6d082c25e16
7
+ data.tar.gz: e00e4fe32d48188761db0f070d55bddf9bd31915f2a4336c2846704aaf4286f1b1e7c132070029a39afa558a264b1badc1734934c47f9d059334a9f06d809416
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.2] - 2025-04-23
9
+
10
+ ### Added
11
+ - Support for additional date keywords:
12
+ - "next week" / "nextweek"
13
+ - "next month" / "nextmonth"
14
+ - "next year" / "nextyear"
15
+ - "this weekend" / "thisweekend"
16
+ - Enhanced parsing to support compound date expressions with spaces
17
+
8
18
  ## [0.0.1] - 2025-04-12
9
19
 
10
20
  ### Added
data/README.md CHANGED
@@ -41,9 +41,29 @@ puts result.date # => <Date: 2023-03-31> (represents today's date)
41
41
  result = Hizuke.parse("call mom yesterday")
42
42
  puts result.text # => "call mom"
43
43
  puts result.date # => <Date: 2023-03-30> (represents yesterday's date)
44
+
45
+ # Parse text with next week's date
46
+ result = Hizuke.parse("team meeting next week")
47
+ puts result.text # => "team meeting"
48
+ puts result.date # => <Date: 2023-04-04> (represents the next Monday)
49
+
50
+ # Parse text with next month's date
51
+ result = Hizuke.parse("vacation next month")
52
+ puts result.text # => "vacation"
53
+ puts result.date # => <Date: 2023-05-01> (represents the first day of the next month)
54
+
55
+ # Parse text with next year's date
56
+ result = Hizuke.parse("conference next year")
57
+ puts result.text # => "conference"
58
+ puts result.date # => <Date: 2024-01-01> (represents the first day of the next year)
59
+
60
+ # Parse text with this weekend's date
61
+ result = Hizuke.parse("hiking this weekend")
62
+ puts result.text # => "hiking"
63
+ puts result.date # => <Date: 2023-04-01> (represents the next Saturday)
44
64
  ```
45
65
 
46
- The parser is case-insensitive and can handle date references located anywhere in the text.
66
+ The parser is case-insensitive and can handle date references located anywhere in the text. It also supports date references with or without spaces (e.g., "nextweek" or "next week").
47
67
 
48
68
  ## Supported Date Keywords
49
69
 
@@ -52,6 +72,10 @@ Currently, the following English date keywords are supported:
52
72
  - `yesterday` - returns yesterday's date
53
73
  - `today` - returns today's date
54
74
  - `tomorrow` - returns tomorrow's date
75
+ - `next week` / `nextweek` - returns the date of the next Monday
76
+ - `next month` / `nextmonth` - returns the first day of the next month
77
+ - `next year` / `nextyear` - returns the first day of the next year
78
+ - `this weekend` / `thisweekend` - returns the date of the upcoming Saturday (or today if it's already the weekend)
55
79
 
56
80
  ## Development
57
81
 
data/lib/hizuke/parser.rb CHANGED
@@ -19,7 +19,15 @@ module Hizuke
19
19
  DATE_KEYWORDS = {
20
20
  "yesterday" => -1,
21
21
  "today" => 0,
22
- "tomorrow" => 1
22
+ "tomorrow" => 1,
23
+ "nextweek" => :next_week,
24
+ "next week" => :next_week,
25
+ "nextmonth" => :next_month,
26
+ "next month" => :next_month,
27
+ "nextyear" => :next_year,
28
+ "next year" => :next_year,
29
+ "thisweekend" => :this_weekend,
30
+ "this weekend" => :this_weekend
23
31
  }.freeze
24
32
 
25
33
  # Parse text containing time references and extract both
@@ -41,18 +49,46 @@ module Hizuke
41
49
  # Check if text is nil or empty
42
50
  raise ParseError, "Input text cannot be nil or empty" if text.nil? || text.empty?
43
51
 
44
- # Split the text into words
52
+ # Try to find compound date expressions (like "next week")
53
+ compound_matches = {}
54
+
55
+ DATE_KEYWORDS.keys.select { |k| k.include?(" ") }.each do |compound_key|
56
+ if text.downcase.include?(compound_key)
57
+ start_idx = text.downcase.index(compound_key)
58
+ end_idx = start_idx + compound_key.length - 1
59
+ compound_matches[compound_key] = [start_idx, end_idx]
60
+ end
61
+ end
62
+
63
+ # If we found compound matches, handle them specially
64
+ unless compound_matches.empty?
65
+ # Use the first match (in case there are multiple)
66
+ match_key, indices = compound_matches.min_by { |_, v| v[0] }
67
+
68
+ # Calculate date based on the keyword
69
+ date_value = DATE_KEYWORDS[match_key]
70
+ date = calculate_date(date_value)
71
+
72
+ # Remove the date expression from the text
73
+ clean_text = text.dup
74
+ clean_text.slice!(indices[0]..indices[1])
75
+ clean_text = clean_text.strip
76
+
77
+ return Result.new(clean_text, date)
78
+ end
79
+
80
+ # Split the text into words (for single-word date references)
45
81
  words = text.split
46
82
 
47
83
  # Find the first date keyword
48
84
  date_word_index = nil
49
- date_offset = nil
85
+ date_value = nil
50
86
 
51
87
  words.each_with_index do |word, index|
52
88
  clean_word = word.downcase.gsub(/[^a-z]/, '')
53
89
  if DATE_KEYWORDS.key?(clean_word)
54
90
  date_word_index = index
55
- date_offset = DATE_KEYWORDS[clean_word]
91
+ date_value = DATE_KEYWORDS[clean_word]
56
92
  break
57
93
  end
58
94
  end
@@ -62,7 +98,7 @@ module Hizuke
62
98
  end
63
99
 
64
100
  # Calculate the date based on the keyword
65
- date = Date.today + date_offset
101
+ date = calculate_date(date_value)
66
102
 
67
103
  # Create the clean text by removing the date keyword
68
104
  clean_words = words.dup
@@ -71,5 +107,34 @@ module Hizuke
71
107
 
72
108
  Result.new(clean_text, date)
73
109
  end
110
+
111
+ private
112
+
113
+ # Calculate the date based on the keyword value
114
+ def calculate_date(date_value)
115
+ if date_value.is_a?(Integer)
116
+ Date.today + date_value
117
+ elsif date_value == :next_week
118
+ # Find next Monday
119
+ days_until_monday = (1 - Date.today.wday) % 7
120
+ # If today is Monday, we want next Monday, not today
121
+ days_until_monday = 7 if days_until_monday == 0
122
+ Date.today + days_until_monday
123
+ elsif date_value == :next_month
124
+ # Return the first day of the next month
125
+ next_month = Date.today >> 1
126
+ Date.new(next_month.year, next_month.month, 1)
127
+ elsif date_value == :next_year
128
+ # Return the first day of the next year
129
+ next_year = Date.today.year + 1
130
+ Date.new(next_year, 1, 1)
131
+ elsif date_value == :this_weekend
132
+ # Calculate days until Saturday
133
+ days_until_saturday = (6 - Date.today.wday) % 7
134
+ # If today is Saturday or Sunday, we're already on the weekend
135
+ days_until_saturday = 0 if days_until_saturday == 0 || days_until_saturday == 6
136
+ Date.today + days_until_saturday
137
+ end
138
+ end
74
139
  end
75
140
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hizuke
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hizuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juraj Maťaše
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-11 00:00:00.000000000 Z
11
+ date: 2025-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -52,8 +52,9 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.21'
55
- description: Parse dates from text containing keywords like 'yesterday', 'today',
56
- and 'tomorrow'
55
+ description: Hizuke is a lightweight utility that extracts dates from text by recognizing
56
+ common time expressions. It cleans the original text and returns both the parsed
57
+ date and the text without the date reference.
57
58
  email:
58
59
  - juraj@hey.com
59
60
  executables: []
@@ -94,5 +95,5 @@ requirements: []
94
95
  rubygems_version: 3.3.7
95
96
  signing_key:
96
97
  specification_version: 4
97
- summary: A simple date parser for text containing time references
98
+ summary: A simple date parser for natural language time references
98
99
  test_files: []