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
Returns a new instance of 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 |
# 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 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 = WordCountAnalyzer::Hyperlink.new(string: string).replace 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: WordCountAnalyzer::Hyperlink.new(string: string).replace).replace end end else if xhtml.eql?('keep') if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period') @processed_string = WordCountAnalyzer::Date.new(string: string).replace else @processed_string = WordCountAnalyzer::Date.new(string: WordCountAnalyzer::Hyperlink.new(string: string).replace).replace end else if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period') @processed_string = WordCountAnalyzer::Date.new(string: WordCountAnalyzer::Xhtml.new(string: string).replace).replace else @processed_string = WordCountAnalyzer::Date.new(string: WordCountAnalyzer::Xhtml.new(string: WordCountAnalyzer::Hyperlink.new(string: string).replace).replace).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
73 74 75 |
# File 'lib/word_count_analyzer/slash.rb', line 73 def backslash_occurences processed_string.scan(BACKSLASH_REGEX).size end |
#forward_slash_occurences ⇒ Object
54 55 56 |
# File 'lib/word_count_analyzer/slash.rb', line 54 def forward_slash_occurences processed_string.scan(FORWARD_SLASH_REGEX).size end |
#includes_backslash? ⇒ Boolean
50 51 52 |
# File 'lib/word_count_analyzer/slash.rb', line 50 def includes_backslash? !(processed_string !~ BACKSLASH_REGEX) end |
#includes_forward_slash? ⇒ Boolean
46 47 48 |
# File 'lib/word_count_analyzer/slash.rb', line 46 def includes_forward_slash? !(processed_string !~ FORWARD_SLASH_REGEX) end |
#replace_backslashes ⇒ Object
77 78 79 80 81 82 |
# File 'lib/word_count_analyzer/slash.rb', line 77 def replace_backslashes return processed_string if processed_string !~ BACKSLASH_REGEX processed_string.gsub!(BACKSLASH_REGEX).each do |match| ' word ' * match.split(/\\+/).length end end |
#replace_forward_slashes ⇒ Object
58 59 60 61 62 63 |
# File 'lib/word_count_analyzer/slash.rb', line 58 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 end |
#replace_forward_slashes_except_dates ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/word_count_analyzer/slash.rb', line 65 def replace_forward_slashes_except_dates return processed_string if processed_string !~ FORWARD_SLASH_REGEX except_date_string = WordCountAnalyzer::Date.new(string: processed_string).replace_number_only_date except_date_string.gsub!(FORWARD_SLASH_REGEX).each do |match| match.split(/\/+/).join(' ') end end |