Class: Nodaire::Indental
- Inherits:
-
Object
- Object
- Nodaire::Indental
- Includes:
- Enumerable
- Defined in:
- lib/nodaire/indental/indental.rb,
lib/nodaire/indental/lexer.rb,
lib/nodaire/indental/parser.rb
Overview
Interface for documents in Indental format.
Indental is a text file format which represents a ‘dictionary-type database’. This format was created by Devine Lu Linvega – see wiki.xxiivv.com/#indental for more information.
Defined Under Namespace
Constant Summary collapse
- INDENT_CHARS_ERROR =
'Indented with non-space characters'
- INDENT_LEVEL_ERROR =
'Unexpected indent level'
Instance Attribute Summary collapse
-
#categories ⇒ Array<String>
readonly
The category names.
-
#data ⇒ Hash
readonly
deprecated
Deprecated.
This will be removed in a future release. Use #to_h instead.
-
#errors ⇒ Array<String>
readonly
An array of zero or more error message strings.
Class Method Summary collapse
-
.parse(source, symbolize_names: false) ⇒ Indental
Parse the document
source
. -
.parse!(source, symbolize_names: false) ⇒ Indental
Parse the document
source
, raising an exception if a parser error occurs.
Instance Method Summary collapse
-
#[](category) ⇒ Hash
Returns the data for a given
category
. -
#each(&block) ⇒ Object
Enumerable.
-
#to_h(*args) ⇒ Hash
Convert the document to a hash.
-
#to_json(*args) ⇒ String
Convert the document to JSON.
-
#valid? ⇒ Boolean
Whether the source was parsed without errors.
Instance Attribute Details
#categories ⇒ Array<String> (readonly)
Returns the category names.
52 53 54 |
# File 'lib/nodaire/indental/indental.rb', line 52 def categories @categories end |
#data ⇒ Hash (readonly)
This will be removed in a future release. Use #to_h instead.
49 50 51 |
# File 'lib/nodaire/indental/indental.rb', line 49 def data @data end |
#errors ⇒ Array<String> (readonly)
Returns an array of zero or more error message strings.
55 56 57 |
# File 'lib/nodaire/indental/indental.rb', line 55 def errors @errors end |
Class Method Details
.parse(source, symbolize_names: false) ⇒ Indental
Parse the document source
.
80 81 82 83 84 |
# File 'lib/nodaire/indental/indental.rb', line 80 def self.parse(source, symbolize_names: false) parser = Parser.new(source, false, symbolize_names: symbolize_names) new(parser) end |
.parse!(source, symbolize_names: false) ⇒ Indental
Parse the document source
, raising an exception if a parser error occurs.
102 103 104 105 106 |
# File 'lib/nodaire/indental/indental.rb', line 102 def self.parse!(source, symbolize_names: false) parser = Parser.new(source, true, symbolize_names: symbolize_names) new(parser) end |
Instance Method Details
#[](category) ⇒ Hash
Returns the data for a given category
.
126 127 128 |
# File 'lib/nodaire/indental/indental.rb', line 126 def [](category) @data[category] end |
#each(&block) ⇒ Object
Enumerable
150 151 152 |
# File 'lib/nodaire/indental/indental.rb', line 150 def each(&block) @data.each(&block) end |
#to_h(*args) ⇒ Hash
Convert the document to a hash.
135 136 137 |
# File 'lib/nodaire/indental/indental.rb', line 135 def to_h(*args) @data.to_h(*args) end |
#to_json(*args) ⇒ String
Convert the document to JSON.
144 145 146 |
# File 'lib/nodaire/indental/indental.rb', line 144 def to_json(*args) @data.to_json(*args) end |
#valid? ⇒ Boolean
Returns whether the source was parsed without errors.
112 113 114 |
# File 'lib/nodaire/indental/indental.rb', line 112 def valid? @errors.empty? end |