Class: WordCountAnalyzer::Slash
- Inherits:
-
Object
- Object
- WordCountAnalyzer::Slash
- Defined in:
- lib/word_count_analyzer/slash.rb
Constant Summary collapse
- FORWARD_SLASH_REGEX =
Rubular: rubular.com/r/AqvcH29sgg
/(?<=\s)(\S+\/)+\S+|(?<=\A)(\S+\/)+\S+/- BACKSLASH_REGEX =
Rubular: rubular.com/r/tuFWtdMs4G
/\S+\\\S+/
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#hyperlink ⇒ Object
readonly
Returns the value of attribute hyperlink.
-
#processed_string ⇒ Object
readonly
Returns the value of attribute processed_string.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#xhtml ⇒ Object
readonly
Returns the value of attribute xhtml.
Instance Method Summary collapse
- #backslash_occurences ⇒ Object
- #forward_slash_occurences ⇒ Object
- #includes_backslash? ⇒ Boolean
- #includes_forward_slash? ⇒ Boolean
-
#initialize(string:, **args) ⇒ Slash
constructor
A new instance of Slash.
- #replace_backslashes ⇒ Object
- #replace_forward_slashes ⇒ Object
- #replace_forward_slashes_except_dates ⇒ Object
Constructor Details
#initialize(string:, **args) ⇒ Slash
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/word_count_analyzer/slash.rb', line 10 def initialize(string:, **args) @string = string @date = args[:date] || nil @xhtml = args[:xhtml] || nil @hyperlink = args[:hyperlink] || nil hyper = WordCountAnalyzer::Hyperlink.new if date.eql?('no_special_treatment') if xhtml.eql?('keep') if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period') @processed_string = string else @processed_string = hyper.replace(string) end else if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period') @processed_string = WordCountAnalyzer::Xhtml.new(string: string).replace else @processed_string = WordCountAnalyzer::Xhtml.new(string: hyper.replace(string)).replace end end else if xhtml.eql?('keep') if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period') @processed_string = WordCountAnalyzer::Date.new.replace(string) else @processed_string = WordCountAnalyzer::Date.new.replace(hyper.replace(string)) end else if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period') @processed_string = WordCountAnalyzer::Date.new.replace(WordCountAnalyzer::Xhtml.new(string: string).replace) else @processed_string = WordCountAnalyzer::Date.new.replace(WordCountAnalyzer::Xhtml.new(string: hyper.replace(string)).replace) end end end end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
9 10 11 |
# File 'lib/word_count_analyzer/slash.rb', line 9 def date @date end |
#hyperlink ⇒ Object (readonly)
Returns the value of attribute hyperlink.
9 10 11 |
# File 'lib/word_count_analyzer/slash.rb', line 9 def hyperlink @hyperlink end |
#processed_string ⇒ Object (readonly)
Returns the value of attribute processed_string.
9 10 11 |
# File 'lib/word_count_analyzer/slash.rb', line 9 def processed_string @processed_string end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
9 10 11 |
# File 'lib/word_count_analyzer/slash.rb', line 9 def string @string end |
#xhtml ⇒ Object (readonly)
Returns the value of attribute xhtml.
9 10 11 |
# File 'lib/word_count_analyzer/slash.rb', line 9 def xhtml @xhtml end |
Instance Method Details
#backslash_occurences ⇒ Object
76 77 78 |
# File 'lib/word_count_analyzer/slash.rb', line 76 def backslash_occurences processed_string.scan(BACKSLASH_REGEX).size end |
#forward_slash_occurences ⇒ Object
55 56 57 |
# File 'lib/word_count_analyzer/slash.rb', line 55 def forward_slash_occurences processed_string.scan(FORWARD_SLASH_REGEX).size end |
#includes_backslash? ⇒ Boolean
51 52 53 |
# File 'lib/word_count_analyzer/slash.rb', line 51 def includes_backslash? !(processed_string !~ BACKSLASH_REGEX) end |
#includes_forward_slash? ⇒ Boolean
47 48 49 |
# File 'lib/word_count_analyzer/slash.rb', line 47 def includes_forward_slash? !(processed_string !~ FORWARD_SLASH_REGEX) end |
#replace_backslashes ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/word_count_analyzer/slash.rb', line 80 def replace_backslashes return processed_string if processed_string !~ BACKSLASH_REGEX processed_string.gsub!(BACKSLASH_REGEX).each do |match| ' word ' * match.split(/\\+/).length end processed_string end |
#replace_forward_slashes ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/word_count_analyzer/slash.rb', line 59 def replace_forward_slashes return processed_string if processed_string !~ FORWARD_SLASH_REGEX processed_string.gsub!(FORWARD_SLASH_REGEX).each do |match| match.split(/\/+/).join(' ') end processed_string end |
#replace_forward_slashes_except_dates ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/word_count_analyzer/slash.rb', line 67 def replace_forward_slashes_except_dates return processed_string if processed_string !~ FORWARD_SLASH_REGEX except_date_string = WordCountAnalyzer::Date.new.replace_number_only_date(processed_string) except_date_string.gsub!(FORWARD_SLASH_REGEX).each do |match| match.split(/\/+/).join(' ') end except_date_string end |