Class: Hibp::Parsers::Password

Inherits:
Object
  • Object
show all
Defined in:
lib/hibp/parsers/password.rb

Overview

Parsers::Password

Used to parse raw data and convert it to the password models

Constant Summary collapse

ROWS_SPLITTER =
"\r\n"
ATTRIBUTES_SPLITTER =
':'

Instance Method Summary collapse

Instance Method Details

#parse_response(response) ⇒ Array<Hibp::Models::Password>

Convert API response raw data to the passwords models. If occurrences of a hash suffix are 0 then it’s fake data added by the add_padding option

Parameters:

  • response

    -

    Contains the suffix of every hash beginning with the specified prefix, followed by a count of how many times it appears in the data set

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hibp/parsers/password.rb', line 22

def parse_response(response)
  data = response.body

  data.split(ROWS_SPLITTER).inject([]) do |array, row|
    suffix, occurrences = row.split(ATTRIBUTES_SPLITTER)

    if occurrences.to_i > 0
      array <<  Models::Password.new(suffix: suffix, occurrences: occurrences.to_i)
    end

    array
  end
end