Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rightmove_blm

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rightmove_blm

  • 0.2.10
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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)

To generate a Rightmove document with version 3i, provide true for the optional parameter international.

document = RightmoveBLM::Document.from_array_of_hashes([{ field1: 'foo', field2: 'bar' }, { field1: 'baz', field2: 'foobar' }], international: true)

FAQs

Package last updated on 11 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc