Class: ConfidentialInfoRedactorLite::Date
- Inherits:
-
Object
- Object
- ConfidentialInfoRedactorLite::Date
- Defined in:
- lib/confidential_info_redactor_lite/date.rb
Constant Summary collapse
- DMY_MDY_REGEX =
Rubular: rubular.com/r/73CZ2HU0q6
/(\d{1,2}(\/|\.|-)){2}\d{4}/
- YMD_YDM_REGEX =
Rubular: rubular.com/r/wFI7dRLK3k
/(?<=\A|\s)\d{4}(\/|\.|-)(\d{1,2}(\/|\.|-)){2}/
- DIGIT_ONLY_YEAR_FIRST_REGEX =
Rubular: rubular.com/r/SRZ27XNlvR
/[12]\d{7}\D/
- DIGIT_ONLY_YEAR_LAST_REGEX =
Rubular: rubular.com/r/mpVSeaKwdY
/\d{4}[12]\d{3}\D/
- JA_DATE_REGEX_LONG =
/[0123456789]+年[0123456789]+月[0123456789]+日/
- JA_DATE_REGEX_SHORT =
/[0123456789]+月[0123456789]+日/
Instance Attribute Summary collapse
-
#dow ⇒ Object
readonly
Returns the value of attribute dow.
-
#dow_abbr ⇒ Object
readonly
Returns the value of attribute dow_abbr.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#months_abbr ⇒ Object
readonly
Returns the value of attribute months_abbr.
Instance Method Summary collapse
- #includes_date?(text) ⇒ Boolean
-
#initialize(dow:, dow_abbr:, months:, months_abbr:) ⇒ Date
constructor
A new instance of Date.
- #occurences(text) ⇒ Object
- #replace(text) ⇒ Object
- #replace_number_only_date(text) ⇒ Object
Constructor Details
#initialize(dow:, dow_abbr:, months:, months_abbr:) ⇒ Date
Returns a new instance of Date.
20 21 22 23 24 25 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 20 def initialize(dow:, dow_abbr:, months:, months_abbr:) @dow = dow @dow_abbr = dow_abbr @months = months @months_abbr = months_abbr end |
Instance Attribute Details
#dow ⇒ Object (readonly)
Returns the value of attribute dow.
19 20 21 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 19 def dow @dow end |
#dow_abbr ⇒ Object (readonly)
Returns the value of attribute dow_abbr.
19 20 21 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 19 def dow_abbr @dow_abbr end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
19 20 21 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 19 def months @months end |
#months_abbr ⇒ Object (readonly)
Returns the value of attribute months_abbr.
19 20 21 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 19 def months_abbr @months_abbr end |
Instance Method Details
#includes_date?(text) ⇒ Boolean
27 28 29 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 27 def includes_date?(text) includes_long_date?(text) || includes_number_only_date?(text) end |
#occurences(text) ⇒ Object
40 41 42 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 40 def occurences(text) replace(text).scan(/<redacted date>/).size end |
#replace(text) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 31 def replace(text) return text unless is_an_array? counter = 0 dow_abbr.map { |day| counter +=1 if text.include?('day') } text = text.gsub(JA_DATE_REGEX_LONG, '<redacted date>').gsub(JA_DATE_REGEX_SHORT, '<redacted date>') text = redact_dates(counter, text) redact_regex(text) end |
#replace_number_only_date(text) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/confidential_info_redactor_lite/date.rb', line 44 def replace_number_only_date(text) text.gsub(DMY_MDY_REGEX, ' <redacted date> ') .gsub(YMD_YDM_REGEX, ' <redacted date> ') .gsub(DIGIT_ONLY_YEAR_FIRST_REGEX, ' <redacted date> ') .gsub(DIGIT_ONLY_YEAR_LAST_REGEX, ' <redacted date> ') end |