rightmove_blm 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adcdd9888460d3dde61600d67eb0a610fbbb971b268220a54d1eb10e66198ac2
4
- data.tar.gz: ed1f65811a5f46e3462891e16db3b9e90a632fc2d7c7466c4d34983c72bfc3cd
3
+ metadata.gz: 27c31f1462ef7ed1cb02253396803510703b7a3f2d14678dd359bd002ff1f113
4
+ data.tar.gz: 2c08d19df9a78f7ceae30a97dbd2be7dba9e6e8d3636779d1cdc3e6db14e75bc
5
5
  SHA512:
6
- metadata.gz: e1777617db9d0efacdfbecc1ba3a07302c76f7e1f5a519847e08e33b4c05c6ec9b4cb3973ae235a8ba4c6e7a04db5657fb21b51ace24c2e1b8b6017c8b2a0e86
7
- data.tar.gz: 73698ab1fb45cdaa69d8628cea64c0ae79595da5803d8c71dc339453047e0058027d4faba928468f432b40bd05c2de50c908c66c832c27c2f5e0c224b93425db
6
+ metadata.gz: b599bc06336d93a1102b5276debb05eb285599f4169dae7fa744070c362e637107221e18a31346af2b6971314f0f1120f095627869a7ac90806023fc129b0922
7
+ data.tar.gz: e1c457877d3163e5b19d2570eab8d07190936cce9132c1588e5f4d8447065e45456c801df245fe8bee3d26142a585bf076e209526930fac0133d496b88f7828d
@@ -3,6 +3,8 @@
3
3
  module RightmoveBLM
4
4
  # A BLM document including its header, definition, and data content.
5
5
  class Document # rubocop:disable Metrics/ClassLength
6
+ BLM_4_FILE_KEYWORDS = %w[HEADER VERSION EOF EOR DEFINITION DATA END].freeze
7
+
6
8
  def self.from_array_of_hashes(array)
7
9
  date = Time.now.utc.strftime('%d-%b-%Y %H:%M').upcase
8
10
  header = { version: '3', eof: '^', eor: '~', 'property count': array.size.to_s, 'generated date': date }
@@ -15,6 +17,7 @@ module RightmoveBLM
15
17
  @definition = definition
16
18
  @name = name
17
19
  initialize_with_data(data) unless data.nil?
20
+ verify_source_file_structure(source) unless source.nil?
18
21
  end
19
22
 
20
23
  def inspect(safe: false, error: nil)
@@ -92,8 +95,8 @@ module RightmoveBLM
92
95
 
93
96
  def contents(section = :data)
94
97
  marker = "##{section.to_s.upcase}#"
95
- start = verify(:start, @source.index(marker)) + marker.size
96
- finish = verify(:end, @source.index('#END#', start)) - 1
98
+ start = verify_marker_presence(:start, @source.index(marker)) + marker.size
99
+ finish = verify_marker_presence(:end, @source.index('#END#', start)) - 1
97
100
  @source[start..finish].strip
98
101
  rescue Encoding::CompatibilityError => e
99
102
  raise_parser_error 'Unable to parse document due to encoding error.', e
@@ -105,12 +108,22 @@ module RightmoveBLM
105
108
  raise_parser_error "Unable to parse document. Error found in header for key `#{key}`", e
106
109
  end
107
110
 
108
- def verify(type, val)
111
+ # INFO : for reverse compatibility. can remove this method and it's calls within this update.
112
+ # verify_file_structure should cover all cases of this method calls
113
+ def verify_marker_presence(type, val)
109
114
  return val unless val.nil?
110
115
 
111
116
  raise_parser_error "Unable to parse document: could not detect #{type} marker."
112
117
  end
113
118
 
119
+ def verify_source_file_structure(source)
120
+ BLM_4_FILE_KEYWORDS.each do |keyword|
121
+ next if source.index(keyword)
122
+
123
+ raise_parser_error "Unable to process document with this structure: could not detect #{keyword} marker."
124
+ end
125
+ end
126
+
114
127
  def generated_date
115
128
  header[:'generated date'] || Time.now.utc.strftime('%d-%b-%Y %H:%M').upcase
116
129
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RightmoveBLM
4
- VERSION = '0.2.4'
4
+ VERSION = '0.2.6'
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary
12
12
  spec.description = 'Parse and generate Rightmove BLM files'
13
- spec.required_ruby_version = '>= 2.7'
13
+ spec.required_ruby_version = '>= 2.7.1'
14
14
 
15
15
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
16
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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
4
+ version: 0.2.6
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-26 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse and generate Rightmove BLM files
14
14
  email: git@bob.frl
@@ -45,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '2.7'
48
+ version: 2.7.1
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="