Class: JustimmoClient::OptionParser Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/justimmo_client/option_parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

default_logger, #logger, rails_logger

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ OptionParser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of OptionParser.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
19
20
# File 'lib/justimmo_client/option_parser.rb', line 11

def initialize(options = {})
  @options = options
  @mappings = {}
  @range_suffix = %i[_min _max]
  @context = nil

  yield self if block_given?

  parse unless options.empty?
end

Instance Attribute Details

#mappingsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/justimmo_client/option_parser.rb', line 9

def mappings
  @mappings
end

#range_suffixObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/justimmo_client/option_parser.rb', line 8

def range_suffix
  @range_suffix
end

Instance Method Details

#add(key, **options, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/justimmo_client/option_parser.rb', line 22

def add(key, **options, &block)
  add_option(key, options, &block)
end

#group(groupname) {|_self| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yields:

  • (_self)

Yield Parameters:



26
27
28
29
30
# File 'lib/justimmo_client/option_parser.rb', line 26

def group(groupname)
  @context = groupname.to_sym
  yield self if block_given?
  @context = nil
end

#parse(options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/justimmo_client/option_parser.rb', line 32

def parse(options = {})
  out = {}

  options.each do |key, value|
    raise JustimmoClient::InvalidOption, key unless @options.key?(key.to_sym)
    group = group_of(key)

    if group
      out[group] ||= {}
      out[group].update(parse_option(key.to_sym, value))
    else
      out.update(parse_option(key.to_sym, value))
    end
  end

  out
end