RCAP 0.2 Released
I’ve just pushed out the RCAP 0.2 gems. This release adds a whole bunch of textual goodness for developers. The main features in this release are
- YAML Support
- inspect/to_s implemented across all RCAP classes
For further information check out the RCAP project page, or you can read some release notes below.
YAML
The major feature in this release is support for YAML. YAML is a plain text serialization format designed to be easily readable and editable by both human and machine. RCAP has custom YAML generation and parsing methods to produce a YAML document that is as human friendly as possible. The following code
alert.to_yaml
will produce the following YAML document
Identifier: 2a1ba96d-16e4-4f52-85ea-0258c1440bd5 Sender: cape_town_disaster_relief@capetown.municipal.za Sent: 2009-11-19T02:41:29+02:00 Status: Actual Message Type: Alert Scope: Public Information: - Language: en-ZA Categories: [Transport, Fire] Event: Liquid Petroleoum Tanker Fire Urgency: Immediate Severity: Severe Certainty: Observed Headline: LIQUID PETROLEOUM TANKER FIRE ON N2 INCOMING FREEWAY Description: |- A liquid petroleoum tanker has caught fire on the N2 incoming freeway 1km after the R300 interchange. Municipal fire fighting crews have been dispatched. Traffic control officers are on the scene and have diverted traffic onto alternate routes.
Alert messgaes can be read in from text files containing data formatted in YAML as generated by Alert#to_yaml.
parsed_alert = RCAP::Alert.from_yaml( alert.to_yaml )
Inspect
I’ve written before on this blog that I believe objects should be as transparent to the end user as possible, and so I’ve tried to apply that to RCAP.
The larger complex classes in RCAP – Alert, Info and Area – have specially designed inspect methods making them easily readable by developers and users when viewed in an IRb command console. Here is an is a log of a console session showing the output for Alert and Info.
1 >> alert 2 => 3 .-------------------------------------------------------------. 4 |ALERT | 5 |-------------------------------------------------------------| 6 |Identifier: a5d154d5-4074-4de5-9ce9-98c6ccb4c5f9 | 7 |Sender: cape_town_disaster_relief@capetown.municipal.za| 8 |Sent: 2009-11-20T12:33:24+02:00 | 9 |Status: Actual | 10 |Message Type: Alert | 11 |Source: | 12 |Scope: Public | 13 |Restriction: | 14 |Addresses: | 15 |Code: | 16 |Note: | 17 |References: | 18 |Incidents: | 19 |Information: | 20 | Liquid Petroleoum Tanker Fire(Immediate/Severe/Observed) | 21 '-------------------------------------------------------------' 22 >> alert.infos.first 23 => 24 .----------------------------------------------------------------------------------. 25 |INFO | 26 |----------------------------------------------------------------------------------| 27 |Language: en-ZA | 28 |Categories: Transport Fire | 29 |Event: Liquid Petroleoum Tanker Fire | 30 |Response Types: | 31 |Urgency: Immediate | 32 |Severity: Severe | 33 |Certainty: Observed | 34 |Audience: | 35 |Event Codes: [] | 36 |Effective: | 37 |Onset: | 38 |Expires: | 39 |Sender Name: | 40 |Headline: LIQUID PETROLEOUM TANKER FIRE ON N2 INCOMING FREEWAY | 41 |Description: | 42 | A liquid petroleoum tanker has caught fire on the N2 incoming freeway 1km | 43 | after the R300 interchange. Municipal fire fighting crews have been dispatched.| 44 | Traffic control officers are on the scene and have diverted traffic onto | 45 | alternate routes. | 46 |Instruction: | 47 |Web: | 48 |Contact: | 49 |Parameters: | 50 | | 51 |Resources: | 52 | | 53 |Area: | 54 | | 55 '----------------------------------------------------------------------------------'
To String
Along with inspect I’ve also implemented logical and consistent (I hope) to_s methods on all RCAP classes. These are mainly designed to produce a label describing the object that can be displayed on a single line. Below are examples for Alert and Info.
1 >> alert.to_s 2 => "cape_town_disaster_relief@capetown.municipal.za/a5d154d5-4074-4de5-9ce9-98c6ccb4c5f9/2009-11-20T12:33:24+02:00" 3 >> alert.infos.first.to_s 4 => "Liquid Petroleoum Tanker Fire(Immediate/Severe/Observed)"
Farrel Lifson is a lead developer at Aimred.