Skip to content

bobf/rightmove_blm

Repository files navigation

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 of RightmoveBLM::Row objects.
  • #valid? - true if no rows have errors, false if 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? - true if document meets the Rightmove International specification, false otherwise.

RightmoveBLM::Row

RightmoveBLM::Row implements:

  • #valid? - true if 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 (nil if 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)

About

Rightmove BLM format processing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages