Class: ImproveTypography::Base

Inherits:
Struct
  • Object
show all
Defined in:
lib/improve_typography/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/improve_typography/base.rb', line 9

def initialize(str, options = {})
  super(str, options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



4
5
6
# File 'lib/improve_typography/base.rb', line 4

def options
  @options
end

#strObject

Returns the value of attribute str

Returns:

  • (Object)

    the current value of str



4
5
6
# File 'lib/improve_typography/base.rb', line 4

def str
  @str
end

Class Method Details

.call(*args) ⇒ Object



5
6
7
# File 'lib/improve_typography/base.rb', line 5

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/improve_typography/base.rb', line 13

def call
  return str unless processor_classes.count > 0

  doc.xpath('.//text()').each do |node|
    processor_classes.each do |processor|
      node.content = processor.call(node.content, options)
    end
  end

  CGI.unescapeHTML(
    doc.to_html.strip[5..-7]
  )
end