Class: WordCountAnalyzer::Date
- Inherits:
-
Object
- Object
- WordCountAnalyzer::Date
- Defined in:
- lib/word_count_analyzer/date.rb
Constant Summary collapse
- DOW =
%w(monday tuesday wednesday thursday friday saturday sunday)- DOW_ABBR =
%w(mon tu tue tues wed th thu thur thurs fri sat sun)- MONTHS =
%w(january february march april may june july august september october november december)- MONTH_ABBR =
%w(jan feb mar apr jun jul aug sep sept oct nov dec)- DMY_MDY_REGEX =
Rubular: rubular.com/r/73CZ2HU0q6
/(\d{1,2}(\/|\.|-)){2}\d{4}\.?/- YMD_YDM_REGEX =
Rubular: rubular.com/r/GWbuWXw4t0
/\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\.?/
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #includes_date? ⇒ Boolean
-
#initialize(string:) ⇒ Date
constructor
A new instance of Date.
- #occurences ⇒ Object
- #replace ⇒ Object
- #replace_number_only_date ⇒ Object
Constructor Details
#initialize(string:) ⇒ Date
Returns a new instance of Date.
20 21 22 |
# File 'lib/word_count_analyzer/date.rb', line 20 def initialize(string:) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
19 20 21 |
# File 'lib/word_count_analyzer/date.rb', line 19 def string @string end |
Instance Method Details
#includes_date? ⇒ Boolean
24 25 26 |
# File 'lib/word_count_analyzer/date.rb', line 24 def includes_date? long_date || number_only_date end |
#occurences ⇒ Object
95 96 97 |
# File 'lib/word_count_analyzer/date.rb', line 95 def occurences replace.scan(/wsdateword/).size end |
#replace ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/word_count_analyzer/date.rb', line 28 def replace new_string = string.dup counter = 0 DOW_ABBR.each do |day| counter +=1 if string.include?('day') end if counter > 0 DOW_ABBR.each do |day| MONTHS.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(\.)*(,)*\s#{Regexp.escape(month)}\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') end MONTH_ABBR.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(\.)*(,)*\s#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') end end DOW.each do |day| MONTHS.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(,)*\s#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/\d{4}\.*\s#{Regexp.escape(month)}\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{4}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*\d+\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{2}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*(\d{4}|\d{2})\.?/i, ' wsdateword ') end MONTH_ABBR.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(,)*\s#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/\d{4}\.*\s#{Regexp.escape(month)}\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{4}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*\d+\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{2}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*(\d{4}|\d{2})\.?/i, ' wsdateword ') end end else DOW.each do |day| MONTHS.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(,)*\s#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/\d{4}\.*\s#{Regexp.escape(month)}\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{4}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*\d+\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{2}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*(\d{4}|\d{2})\.?/i, ' wsdateword ') end MONTH_ABBR.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(,)*\s#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') .gsub(/\d{4}\.*\s#{Regexp.escape(month)}\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{4}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*\d+\.?/i, ' wsdateword ') .gsub(/#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*\.?/i, ' wsdateword ') .gsub(/\d{2}(\.|-|\/)*#{Regexp.escape(month)}(\.|-|\/)*(\d{4}|\d{2})\.?/i, ' wsdateword ') end end DOW_ABBR.each do |day| MONTHS.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(\.)*(,)*\s#{Regexp.escape(month)}\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') end MONTH_ABBR.each do |month| new_string = new_string.gsub(/#{Regexp.escape(day)}(\.)*(,)*\s#{Regexp.escape(month)}(\.)*\s\d+(rd|th)*(,)*\s\d{4}\.?/i, ' wsdateword ') end end end new_string = new_string.gsub(DMY_MDY_REGEX, ' wsdateword ') .gsub(YMD_YDM_REGEX, ' wsdateword ') .gsub(DIGIT_ONLY_YEAR_FIRST_REGEX, ' wsdateword ') .gsub(DIGIT_ONLY_YEAR_LAST_REGEX, ' wsdateword ') end |
#replace_number_only_date ⇒ Object
99 100 101 102 103 104 |
# File 'lib/word_count_analyzer/date.rb', line 99 def replace_number_only_date string.gsub(DMY_MDY_REGEX, ' wsdateword ') .gsub(YMD_YDM_REGEX, ' wsdateword ') .gsub(DIGIT_ONLY_YEAR_FIRST_REGEX, ' wsdateword ') .gsub(DIGIT_ONLY_YEAR_LAST_REGEX, ' wsdateword ') end |