Class: Translatomatic::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/translatomatic/option.rb

Overview

Stores details about command line and object constructor options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Translatomatic::Option

Create a new option

Parameters:

  • data (Hash<Symbol,Object>) (defaults to: {})

    Attributes as above



31
32
33
34
35
36
37
38
39
40
# File 'lib/translatomatic/option.rb', line 31

def initialize(data = {})
  @name = data[:name]
  @required = data[:required]
  @use_env = data[:use_env]
  @description = data[:desc]
  @hidden = data[:hidden]
  @default = data[:default]
  @type = data[:type] || :string
  @data = data
end

Instance Attribute Details

#defaultObject (readonly)

Returns The default value for this option.

Returns:

  • (Object)

    The default value for this option



26
27
28
# File 'lib/translatomatic/option.rb', line 26

def default
  @default
end

#descriptionString (readonly)

Returns Description of the option.

Returns:

  • (String)

    Description of the option



15
16
17
# File 'lib/translatomatic/option.rb', line 15

def description
  @description
end

#hiddenboolean (readonly)

Returns If true, the option does not appear on the command line but it can be used in configuration settings.

Returns:

  • (boolean)

    If true, the option does not appear on the command line but it can be used in configuration settings



19
20
21
# File 'lib/translatomatic/option.rb', line 19

def hidden
  @hidden
end

#nameString (readonly)

Returns Name of the option.

Returns:

  • (String)

    Name of the option



5
6
7
# File 'lib/translatomatic/option.rb', line 5

def name
  @name
end

#requiredboolean (readonly)

Returns True if this option is required.

Returns:

  • (boolean)

    True if this option is required



8
9
10
# File 'lib/translatomatic/option.rb', line 8

def required
  @required
end

#typeSymbol (readonly)

Returns Type of option, one of: :string, :hash, :array, :numeric, or :boolean.

Returns:

  • (Symbol)

    Type of option, one of: :string, :hash, :array, :numeric, or :boolean



23
24
25
# File 'lib/translatomatic/option.rb', line 23

def type
  @type
end

#use_envboolean (readonly)

Returns If true, the option can be set via an environment variable corresponding to the uppercased version of #name.

Returns:

  • (boolean)

    If true, the option can be set via an environment variable corresponding to the uppercased version of #name.



12
13
14
# File 'lib/translatomatic/option.rb', line 12

def use_env
  @use_env
end

Class Method Details

.options_from_object(object) ⇒ Array<Translatomatic::Option>

Retrieve all options from an object or list of objects.

Parameters:

  • object (#options, Array<#options>)

    Options source

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/translatomatic/option.rb', line 50

def self.options_from_object(object)
  options = []
  if object.respond_to?(:options)
    options += options_from_object(object.options)
  elsif object.kind_of?(Array)
    object.each do |item|
      if item.kind_of?(Translatomatic::Option)
        options << item
      elsif item.respond_to?(:options)
        options += options_from_object(item.options)
      end
    end
  end
  options
end

Instance Method Details

#to_hashHash

Returns Option data as a hash.

Returns:

  • (Hash)

    Option data as a hash



43
44
45
# File 'lib/translatomatic/option.rb', line 43

def to_hash
  @data
end