Class: HTTPAuth::Digest::Conversions

Inherits:
Object
  • Object
show all
Defined in:
lib/httpauth/digest.rb

Overview

Conversion for a number of internal data structures to and from directives in the headers. Implementations shouldn’t have to call any methods on Conversions.

Class Method Summary collapse

Class Method Details

.bool_to_str(bool) ⇒ Object

Creates a string value from a boolean => ‘true’ or ‘false’



552
553
554
# File 'lib/httpauth/digest.rb', line 552

def bool_to_str(bool)
  bool ? 'true' : 'false'
end

.comma_quoted_string_to_list(string) ⇒ Object

Create a list from a quoted comma separated string of items



571
572
573
# File 'lib/httpauth/digest.rb', line 571

def comma_quoted_string_to_list(string)
  unquote_string(string).split ','
end

.hex_to_int(str) ⇒ Object

Creates an int value from hex values



537
538
539
# File 'lib/httpauth/digest.rb', line 537

def hex_to_int(str)
  "0x#{str}".hex
end

.int_to_hex(i) ⇒ Object

Creates a hex value in a string from an integer



542
543
544
# File 'lib/httpauth/digest.rb', line 542

def int_to_hex(i)
  i.to_s(16).rjust 8, '0'
end

.list_to_comma_quoted_string(list) ⇒ Object

Creates a quoted string with comma separated items from a list



567
568
569
# File 'lib/httpauth/digest.rb', line 567

def list_to_comma_quoted_string(list)
  quote_string list.join(',')
end

.list_to_space_quoted_string(list) ⇒ Object

Creates a quoted string with space separated items from a list



557
558
559
# File 'lib/httpauth/digest.rb', line 557

def list_to_space_quoted_string(list)
  quote_string list.join(' ')
end

.quote_string(str) ⇒ Object

Adds quotes around the string



527
528
529
# File 'lib/httpauth/digest.rb', line 527

def quote_string(str)
  "\"#{str.gsub(/\"/, '')}\""
end

.space_quoted_string_to_list(string) ⇒ Object

Creates a list from a quoted space separated string of items



562
563
564
# File 'lib/httpauth/digest.rb', line 562

def space_quoted_string_to_list(string)
  unquote_string(string).split ' '
end

.str_to_bool(str) ⇒ Object

Creates a boolean value from a string => true or false



547
548
549
# File 'lib/httpauth/digest.rb', line 547

def str_to_bool(str)
  str == 'true'
end

.unquote_string(str) ⇒ Object

Removes quotes from around a string



532
533
534
# File 'lib/httpauth/digest.rb', line 532

def unquote_string(str)
  str =~ /^\"([^\"]*)\"$/ ? Regexp.last_match[1] : str
end