Rightmove BLM
A simple parser for the Rightmove .blm Bulk Load Mass file format.
Originally forked from the BLM gem by Robert May.
This library is not affiliated with or endorsed by Rightmove Plc in any way.
Usage
Loading a BLM file
RightmoveBLM::Document
Load a BLM file by passing the source parameter to RightmoveBLM::Document.new:
blm = RightmoveBLM::Document.new(source: File.read('example_data.blm'))
RightmoveBLM::Document.new also receives an optional argument name which is recommended for all documents to assist in tracking errors when processing many documents, e.g.:
blm = RightmoveBLM::Document.new(source: File.read('example_data.blm'), name: 'example_data.blm')
This name will be included in all parser error messages.
The returned RightmoveBLM::Document instance implements:
#header- the header containing information about the document's structure.#definition- the field list contained in the document.#rows- an array ofRightmoveBLM::Rowobjects.#valid?-trueif no rows have errors,falseif any rows have errors.#errors- all error messages for all invalid rows.#version- the version of the document format as a string (e.g.'3').#international?-trueif document meets the Rightmove International specification,falseotherwise.
RightmoveBLM::Row
RightmoveBLM::Row implements:
#valid?-trueif no errors were encountered, false otherwise.#errors- an array of error strings (empty if no errors present).#to_h(or#attributes) - a hash of row attributes (nilif errors encountered).#method_missing- allows accessing row attributes by dot notation (e.g.row.address_1).
Example
blm.data.select(&:valid?).each do |row|
puts row.address_1
puts row.to_h
end
blm.data.reject(&:valid?).each do |row|
puts "Errors: #{row.errors.join(', ')}"
end
Writing BLM data
An array of hashes can be converted to a RightmoveBLM::Document object which can then be used to create an output string by calling #to_blm.
The keys from the first hash in the provided array are used to provide the field definition. All hashes must contain the same keys.
document = RightmoveBLM::Document.from_array_of_hashes([{ field1: 'foo', field2: 'bar' }, { field1: 'baz', field2: 'foobar' }])
File.write('my_data.blm', document.to_blm)