Class: WordCountAnalyzer::Xhtml
- Inherits:
-
Object
- Object
- WordCountAnalyzer::Xhtml
- Defined in:
- lib/word_count_analyzer/xhtml.rb
Constant Summary collapse
- XHTML_REGEX =
Rubular: rubular.com/r/ENrVFMdJ8v
/<\/?[^>]*>/
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #count_difference_word_boundary ⇒ Object
- #includes_xhtml? ⇒ Boolean
-
#initialize(string:) ⇒ Xhtml
constructor
A new instance of Xhtml.
- #occurrences ⇒ Object
- #replace ⇒ Object
Constructor Details
#initialize(string:) ⇒ Xhtml
Returns a new instance of Xhtml.
6 7 8 |
# File 'lib/word_count_analyzer/xhtml.rb', line 6 def initialize(string:) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
5 6 7 |
# File 'lib/word_count_analyzer/xhtml.rb', line 5 def string @string end |
Instance Method Details
#count_difference_word_boundary ⇒ Object
18 19 20 |
# File 'lib/word_count_analyzer/xhtml.rb', line 18 def count_difference_word_boundary string.split(/\s+/).size - replace.strip.split(/\s+/).size end |
#includes_xhtml? ⇒ Boolean
10 11 12 |
# File 'lib/word_count_analyzer/xhtml.rb', line 10 def includes_xhtml? !(string !~ XHTML_REGEX) end |
#occurrences ⇒ Object
22 23 24 |
# File 'lib/word_count_analyzer/xhtml.rb', line 22 def occurrences string.gsub(XHTML_REGEX, ' wsxhtmlword ').scan(/wsxhtmlword/).size / 2 end |
#replace ⇒ Object
14 15 16 |
# File 'lib/word_count_analyzer/xhtml.rb', line 14 def replace string.gsub(XHTML_REGEX, ' ') end |