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.

Defined Under Namespace

Classes: DuplicateKeyGroup, InvalidOption, InvalidValue

Constant Summary collapse

OptionParserError =

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

Raised when option parsing fails

Class.new(StandardError)

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:



34
35
36
37
38
39
40
41
42
43
# File 'lib/justimmo_client/option_parser.rb', line 34

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.



32
33
34
# File 'lib/justimmo_client/option_parser.rb', line 32

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.



31
32
33
# File 'lib/justimmo_client/option_parser.rb', line 31

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.



45
46
47
# File 'lib/justimmo_client/option_parser.rb', line 45

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:



49
50
51
52
53
# File 'lib/justimmo_client/option_parser.rb', line 49

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.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/justimmo_client/option_parser.rb', line 55

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

  options.each do |key, value|
    raise 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).reject { |_k, v| v.nil? })
    else
      out.update(parse_option(key.to_sym, value).reject { |_k, v| v.nil? })
    end
  end

  out
end