Class: HParser::Block::Pair
- Inherits:
-
Object
- Object
- HParser::Block::Pair
- Defined in:
- lib/hparser/block/pair.rb
Overview
Some formats have common structure.
Qutoe is defined as
>>
quoted string
<<
Pre is defiend as
>|
plain text
|<
In short,some format is different in begining/ending string. So this class have basic structure for that format.
Remark:Strictly,quote is defined as “from the line that contain only ‘>>’ to the line that contain only ‘<<’”
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Class Method Summary collapse
- .get(scanner, from, to) ⇒ Object
-
.spliter(from, to) ⇒ Object
make parser by begin/end-ing string.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#initialize(content) ⇒ Pair
constructor
A new instance of Pair.
Constructor Details
#initialize(content) ⇒ Pair
Returns a new instance of Pair.
58 59 60 |
# File 'lib/hparser/block/pair.rb', line 58 def initialize(content) @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
57 58 59 |
# File 'lib/hparser/block/pair.rb', line 57 def content @content end |
Class Method Details
.get(scanner, from, to) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hparser/block/pair.rb', line 26 def self.get(scanner,from,to) from_q = Regexp.quote from to_q = Regexp.quote to if scanner.scan(/^#{from_q}\s*?$/) lines = [] until scanner.scan(/^#{to_q}\s*?$/) do matched = scanner.scan(/.*/) if matched lines << matched else break end end return lines.join("\n") end end |
.spliter(from, to) ⇒ Object
make parser by begin/end-ing string
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hparser/block/pair.rb', line 44 def self.spliter(from,to) module_eval <<-"END" def self.parse(scanner,context,inlines) content = get(scanner,"#{from}","#{to}") if content then self.new inlines.parse(content, context) else nil end end END end |
Instance Method Details
#==(o) ⇒ Object
62 63 64 |
# File 'lib/hparser/block/pair.rb', line 62 def ==(o) self.class == o.class and self.content == o.content end |