Class: Agate::Parser
- Inherits:
-
Object
- Object
- Agate::Parser
- Defined in:
- lib/agate/parser.rb
Constant Summary collapse
- DEFAULTS =
Default options
{ :delimiters => "【】", :formatter => :plain }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse(text) ⇒ Object
Parse ‘text` and return it with ruby character markup.
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
14 15 16 17 18 19 |
# File 'lib/agate/parser.rb', line 14 def initialize( = {}) = DEFAULTS.merge() @formatter = Agate.retrieve_formatter([:formatter]) @formatter ||= Agate::Formatter::Plain end |
Instance Method Details
#parse(text) ⇒ Object
Parse ‘text` and return it with ruby character markup
22 23 24 25 26 27 28 |
# File 'lib/agate/parser.rb', line 22 def parse(text) first = Regexp.escape([:delimiters][0]) last = Regexp.escape([:delimiters][-1]) expr = /(\p{Han}+)(#{first})([\p{Hiragana}\p{Katakana}]+)(#{last})/u text.gsub(expr) { |match| @formatter.format($~) } end |