Class: AutoCorrect

Inherits:
Object
  • Object
show all
Defined in:
lib/auto-correct.rb,
lib/auto-correct/base.rb,
lib/auto-correct/html.rb,
lib/auto-correct/format.rb,
lib/auto-correct/version.rb,
lib/auto-correct/strategery.rb

Defined Under Namespace

Classes: Strategery

Constant Summary collapse

CJK =
'\p{Han}|\p{Hangul}|\p{Hanunoo}|\p{Katakana}|\p{Hiragana}|\p{Bopomofo}'
SPACE =
"[ ]"
DASH_HAN_RE =
/([#{CJK})】」》”’])(-+)([#{CJK}(【「《“‘])/
LEFT_QUOTE_RE =
/#{SPACE}([(【「《])/
RIGHT_QUOTE_RE =
/([)】」》])#{SPACE}/
VERSION =
"1.0.0"
@@strategies =
[]

Class Method Summary collapse

Class Method Details

.format(str) ⇒ Object



25
26
27
28
29
30
# File 'lib/auto-correct/format.rb', line 25

def format(str)
  strategies.each do |s|
    str = s.format(str)
  end
  space_dash_with_hans(str)
end

.format_html(html) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/auto-correct/html.rb', line 5

def format_html(html)
  doc = Nokogiri::HTML(html)
  doc.traverse do |node|
    next unless node.node_type == Nokogiri::XML::Node::TEXT_NODE
    node.content = AutoCorrect.format(node.content)
  end
  doc.css("body").inner_html
end

.rule(one, other, space: false, reverse: false) ⇒ Object



5
6
7
# File 'lib/auto-correct/base.rb', line 5

def rule(one, other, space: false, reverse: false)
  @@strategies << AutoCorrect::Strategery.new(one, other, space: space, reverse: reverse)
end

.strategiesObject



9
10
11
# File 'lib/auto-correct/base.rb', line 9

def strategies
  @@strategies
end