Class: Card::Content::Parser

Inherits:
Object
  • Object
show all
Defined in:
card/lib/card/content/parser.rb

Overview

The Content::Parser breaks content strings into an Array of “chunks”, each of which may be an instance of a Chunk class or a simple String.

Instance Method Summary collapse

Constructor Details

#initialize(chunk_list, content_object) ⇒ Parser

to be used in parsing

Parameters:

  • chunk_list (Symbol)

    name of registered list of chunk classes

  • content_object (Card::Content)

See Also:

  • Card::Chunk.register_list


10
11
12
13
# File 'card/lib/card/content/parser.rb', line 10

def initialize chunk_list, content_object
  @content_object = content_object
  @chunk_list = chunk_list
end

Instance Method Details

#parse(content) ⇒ Array

break content string into an array of chunk objects and strings

Parameters:

  • content (String)

Returns:

  • (Array)


18
19
20
21
22
23
24
25
26
27
# File 'card/lib/card/content/parser.rb', line 18

def parse content
  @content = content
  @chunks = []
  return @chunks unless content.is_a? String

  @position = @last_position = 0
  @interval_string = ""
  parse_chunks
  @chunks
end