class Hibp::Parsers::Password

Parsers::Password

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

Constants

ATTRIBUTES_SPLITTER
ROWS_SPLITTER

Public Instance Methods

parse_response(response) click to toggle source

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

@param 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

@return [Array<Hibp::Models::Password>]

# 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