Class: Krikri::Parser

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

Overview

Provides a generic interface for accessing properties from OriginalRecords. Implement the interface, and that of `Value` on an record-type basis.

parser = Krikri::Parser::MyParser.new(record)
parser.root # => #<Krikri::MyParser::Value:0x007f861888fea0>

Direct Known Subclasses

JsonParser, XmlParser

Defined Under Namespace

Classes: Value, ValueArray

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Parser

Returns a new instance of Parser

Parameters:


15
16
17
# File 'lib/krikri/parser.rb', line 15

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record


10
11
12
# File 'lib/krikri/parser.rb', line 10

def record
  @record
end

#rootObject (readonly)

Returns the value of attribute root


10
11
12
# File 'lib/krikri/parser.rb', line 10

def root
  @root
end

Class Method Details

.parse(record, *args) ⇒ Krikri::Parser

Instantiates a parser object to wrap the record. Returns the record as is if it is already parsed.

Parameters:

Returns:


27
28
29
# File 'lib/krikri/parser.rb', line 27

def self.parse(record, *args)
  record.is_a?(Krikri::Parser) ? record : new(record, *args)
end