Module: LZWS::Option

Defined in:
lib/lzws/option.rb

Constant Summary collapse

DEFAULT_BUFFER_LENGTH =
0

Class Method Summary collapse

Class Method Details

.get_compressor_options(options, buffer_length_names) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lzws/option.rb', line 13

def self.get_compressor_options(options, buffer_length_names)
  Validation.validate_hash options

  buffer_length_defaults = buffer_length_names.each_with_object({}) { |name, defaults| defaults[name] = DEFAULT_BUFFER_LENGTH }
  options                = buffer_length_defaults.merge options

  buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }

  max_code_bit_length = options[:max_code_bit_length]
  unless max_code_bit_length.nil?
    Validation.validate_positive_integer max_code_bit_length
    raise ValidateError, "invalid max code bit length" if
      max_code_bit_length < LOWEST_MAX_CODE_BIT_LENGTH || max_code_bit_length > BIGGEST_MAX_CODE_BIT_LENGTH
  end

  without_magic_header = options[:without_magic_header]
  Validation.validate_bool without_magic_header unless without_magic_header.nil?

  block_mode = options[:block_mode]
  Validation.validate_bool block_mode unless block_mode.nil?

  msb = options[:msb]
  Validation.validate_bool msb unless msb.nil?

  unaligned_bit_groups = options[:unaligned_bit_groups]
  Validation.validate_bool unaligned_bit_groups unless unaligned_bit_groups.nil?

  quiet = options[:quiet]
  Validation.validate_bool quiet unless quiet.nil?

  options
end

.get_decompressor_options(options, buffer_length_names) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/lzws/option.rb', line 46

def self.get_decompressor_options(options, buffer_length_names)
  Validation.validate_hash options

  buffer_length_defaults = buffer_length_names.each_with_object({}) { |name, defaults| defaults[name] = DEFAULT_BUFFER_LENGTH }
  options                = buffer_length_defaults.merge options

  buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }

  without_magic_header = options[:without_magic_header]
  Validation.validate_bool without_magic_header unless without_magic_header.nil?

  msb = options[:msb]
  Validation.validate_bool msb unless msb.nil?

  unaligned_bit_groups = options[:unaligned_bit_groups]
  Validation.validate_bool unaligned_bit_groups unless unaligned_bit_groups.nil?

  quiet = options[:quiet]
  Validation.validate_bool quiet unless quiet.nil?

  options
end