Class: Hibp::Parsers::Password
- Inherits:
-
Object
- Object
- Hibp::Parsers::Password
- 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
-
#parse_response(response) ⇒ Array<Hibp::Models::Password>
Convert API response raw data to the passwords models.
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
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 |