Skip to content

Commit 1e64871

Browse files
committed
Made the insert recurs before into a regexp in a substitution, rather
than a "lame" method
1 parent 5d522da commit 1e64871

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

lib/nickel/nlp_query.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def query_formatting
4141
Substitutions::Weekdays.apply(self)
4242
Substitutions::Months.apply(self)
4343
Substitutions::Numbers.apply(self)
44-
insert_repeats_before_words_indicating_recurrence_lame
4544
query_str.concat(' ')
4645
@after_formatting = query_str.dup # save current state
4746
end
@@ -79,16 +78,6 @@ def query_pre_processing
7978
standardize_input
8079
end
8180

82-
def insert_repeats_before_words_indicating_recurrence_lame
83-
comps = query_str.split
84-
(daily_index = comps.index('daily')) && comps[daily_index - 1] != 'repeats' && comps[daily_index] = 'repeats daily'
85-
(weekly_index = comps.index('weekly')) && comps[weekly_index - 1] != 'repeats' && comps[weekly_index] = 'repeats weekly'
86-
(monthly_index = comps.index('monthly')) && comps[monthly_index - 1] != 'repeats' && comps[monthly_index] = 'repeats monthly'
87-
if (rejoin = comps.join(' ')) != query_str
88-
nsub!(/.+/, rejoin)
89-
end
90-
end
91-
9281
def to_s
9382
query_str
9483
end

lib/nickel/substitutions/repetition.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class Repetition < Substitutor
2121
[/fridays/, 'every fri'],
2222
[/saturdays/, 'every sat'],
2323
[/sundays/, 'every sun'],
24+
[/(?<!repeats )daily/, 'repeats daily'],
25+
[/(?<!repeats )weekly/, 'repeats weekly'],
26+
[/(?<!repeats )monthly/, 'repeats monthly'],
2427
]
2528
end
2629
end

0 commit comments

Comments
 (0)