-
Notifications
You must be signed in to change notification settings - Fork 0
Parser
Leandro Segovia edited this page Feb 23, 2018
·
2 revisions
Once you have defined the behavior of your parser using the DSL, you can use it:
parser = SuperheroesParser.new
result = parser.run("/some_path/superhero.xls"); #=> #<Enumerator: ...>
row = result.next
In parser/file context:
-
parser.valid_file?
: returns true if some file validation fails. -
parser.file_error
: returns a symbol with the error name if some file validation fails. -
parser.run(file_path)
: it starts the parsing.
In row context:
-
row.idx
: the row number matching the xls/csv file. -
row.errors?
: returns true if some row's attribute has errors. -
row.errors
: returns a hash with errors with the format:{ column1: :error_name, column2: :error_name }
-
row.attribute_error?(:some_attribute_name)
: returns true if the given attribute has errors on that row. -
row.add_attribute(:some_attribute_name)
: to add a custom getter/setter with a custom value. -
row.publisher
: having acolumn(:publisher, name: "Publisher")
. Parxer will generate a getter/setter for each column defined with the DSL.