Class: Raev::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/raev/article.rb

Constant Summary collapse

REGEX_NODE_EMPTY =
/\A *\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Article

Returns a new instance of Article.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/raev/article.rb', line 10

def initialize(body)
  @doc = Nokogiri::HTML::DocumentFragment.parse(
    replace_non_breaking_space(body)
  )
  
  replace_divs_with_paragraphs(@doc)
  remove_empty_paragraphs(@doc)
  remove_extra_linebreaks(@doc)

  @body = @doc.to_s.gsub("\n".freeze, "".freeze)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/raev/article.rb', line 7

def body
  @body
end

#docObject (readonly)

Returns the value of attribute doc.



8
9
10
# File 'lib/raev/article.rb', line 8

def doc
  @doc
end