rightmove_blm 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/rightmove_blm/document.rb +24 -7
- data/lib/rightmove_blm/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d47e3147eefd5503a6f72579b89a3009c2cd54f12e8103403d320b25f11aa414
|
4
|
+
data.tar.gz: 1e74f8d0a87a1ba9896525eec622d4b86612ec4c218807740b3c1a90642bd423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08f19c96d3dc41020b8d1750c3e1863745984128191911c3144319f7cbe884402288a9ef944f0f72c043cb7ce3246d2d87bebbbbdaec340243090aefcc65d0b1'
|
7
|
+
data.tar.gz: 1a2f3a7879e88d59ed174d9b9c46905ab8c5280737b17050c04aa20c86d93fdaf0a3cd43a76dca0894a5c2f754ef3671527c3e9ef4163440f965a126ff1bee59
|
data/README.md
CHANGED
@@ -18,6 +18,14 @@ Load a BLM file by passing the `source` parameter to `RightmoveBLM::Document.new
|
|
18
18
|
blm = RightmoveBLM::Document.new(source: File.read('example_data.blm'))
|
19
19
|
```
|
20
20
|
|
21
|
+
`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.:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
blm = RightmoveBLM::Document.new(source: File.read('example_data.blm'), name: 'example_data.blm')
|
25
|
+
```
|
26
|
+
|
27
|
+
This name will be included in all parser error messages.
|
28
|
+
|
21
29
|
The returned `RightmoveBLM::Document` instance implements:
|
22
30
|
|
23
31
|
* `#header` - the header containing information about the document's structure.
|
@@ -9,15 +9,22 @@ module RightmoveBLM
|
|
9
9
|
new(header: header, definition: array.first.keys.map(&:to_sym), data: array)
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(source: nil, header: nil, definition: nil, data: nil)
|
13
|
-
@source = source
|
12
|
+
def initialize(source: nil, header: nil, definition: nil, data: nil, name: nil)
|
13
|
+
@source = source || data
|
14
14
|
@header = header
|
15
15
|
@definition = definition
|
16
|
+
@name = name
|
16
17
|
initialize_with_data(data) unless data.nil?
|
17
18
|
end
|
18
19
|
|
19
|
-
def inspect
|
20
|
-
|
20
|
+
def inspect(safe: false, error: nil)
|
21
|
+
name = @name.nil? ? nil : %( document="#{@name}")
|
22
|
+
error_string = error.nil? ? nil : %( error="#{error}")
|
23
|
+
basic = %(<##{self.class.name}#{name}#{error_string}>)
|
24
|
+
return basic if safe
|
25
|
+
|
26
|
+
"<##{self.class.name}#{name}#{error_string} version=#{version} " \
|
27
|
+
"rows=#{rows.size} valid=#{valid?} errors=#{errors.size}>"
|
21
28
|
end
|
22
29
|
|
23
30
|
def to_s
|
@@ -39,7 +46,7 @@ module RightmoveBLM
|
|
39
46
|
key, _, value = line.partition(':')
|
40
47
|
next nil if value.nil?
|
41
48
|
|
42
|
-
[key
|
49
|
+
[normalized_key(key), value.tr("'", '').strip]
|
43
50
|
end.compact.to_h
|
44
51
|
end
|
45
52
|
|
@@ -86,14 +93,20 @@ module RightmoveBLM
|
|
86
93
|
def contents(section = :data)
|
87
94
|
marker = "##{section.to_s.upcase}#"
|
88
95
|
start = verify(:start, @source.index(marker)) + marker.size
|
89
|
-
finish = verify(:end, @source.index('#', start)) - 1
|
96
|
+
finish = verify(:end, @source.index('#END#', start)) - 1
|
90
97
|
@source[start..finish].strip
|
91
98
|
end
|
92
99
|
|
100
|
+
def normalized_key(key)
|
101
|
+
key.strip.downcase.to_sym
|
102
|
+
rescue ArgumentError => e
|
103
|
+
raise_parser_error "Unable to parse document. Error found in header for key `#{key}`", e
|
104
|
+
end
|
105
|
+
|
93
106
|
def verify(type, val)
|
94
107
|
return val unless val.nil?
|
95
108
|
|
96
|
-
|
109
|
+
raise_parser_error "Unable to parse document: could not detect #{type} marker."
|
97
110
|
end
|
98
111
|
|
99
112
|
def generated_date
|
@@ -112,5 +125,9 @@ module RightmoveBLM
|
|
112
125
|
def data_string
|
113
126
|
['#DATA#', *data.map { |row| "#{row.attributes.values.join('|')}~" }, '#END#']
|
114
127
|
end
|
128
|
+
|
129
|
+
def raise_parser_error(message, cause = nil)
|
130
|
+
raise ParserError, "#{inspect(safe: true)}: #{message} #{cause}"
|
131
|
+
end
|
115
132
|
end
|
116
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightmove_blm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parse and generate Rightmove BLM files
|
14
14
|
email: git@bob.frl
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.4.13
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: A parser for the Rightmove .blm format
|