Class: WordCountAnalyzer::Xhtml

Inherits:
Object
  • Object
show all
Defined in:
lib/word_count_analyzer/xhtml.rb

Constant Summary collapse

XHTML_REGEX =
/<\/?[^>]*>/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#stringObject (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_boundaryObject



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

Returns:

  • (Boolean)


10
11
12
# File 'lib/word_count_analyzer/xhtml.rb', line 10

def includes_xhtml?
  !(string !~ XHTML_REGEX)
end

#occurrencesObject



22
23
24
# File 'lib/word_count_analyzer/xhtml.rb', line 22

def occurrences
  string.gsub(XHTML_REGEX, ' wsxhtmlword ').scan(/wsxhtmlword/).size / 2
end

#replaceObject



14
15
16
# File 'lib/word_count_analyzer/xhtml.rb', line 14

def replace
  string.gsub(XHTML_REGEX, ' ')
end