Class: Translatomatic::Option
- Inherits:
-
Object
- Object
- Translatomatic::Option
- Defined in:
- lib/translatomatic/option.rb
Overview
Stores details about command line and object constructor options
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
The default value for this option.
-
#description ⇒ String
readonly
Description of the option.
-
#hidden ⇒ boolean
readonly
If true, the option does not appear on the command line but it can be used in configuration settings.
-
#name ⇒ String
readonly
Name of the option.
-
#required ⇒ boolean
readonly
True if this option is required.
-
#type ⇒ Symbol
readonly
Type of option, one of: :string, :hash, :array, :numeric, or :boolean.
-
#use_env ⇒ boolean
readonly
If true, the option can be set via an environment variable corresponding to the uppercased version of #name.
Class Method Summary collapse
-
.options_from_object(object) ⇒ Array<Translatomatic::Option>
Retrieve all options from an object or list of objects.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Translatomatic::Option
constructor
Create a new option.
-
#to_hash ⇒ Hash
Option data as a hash.
Constructor Details
#initialize(data = {}) ⇒ Translatomatic::Option
Create a new option
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
#default ⇒ Object (readonly)
Returns The default value for this option.
26 27 28 |
# File 'lib/translatomatic/option.rb', line 26 def default @default end |
#description ⇒ String (readonly)
Returns Description of the option.
15 16 17 |
# File 'lib/translatomatic/option.rb', line 15 def description @description end |
#hidden ⇒ boolean (readonly)
Returns 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 |
#name ⇒ String (readonly)
Returns Name of the option.
5 6 7 |
# File 'lib/translatomatic/option.rb', line 5 def name @name end |
#required ⇒ boolean (readonly)
Returns True if this option is required.
8 9 10 |
# File 'lib/translatomatic/option.rb', line 8 def required @required end |
#type ⇒ Symbol (readonly)
Returns 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_env ⇒ boolean (readonly)
Returns 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/translatomatic/option.rb', line 50 def self.(object) = [] if object.respond_to?(:options) += (object.) elsif object.kind_of?(Array) object.each do |item| if item.kind_of?(Translatomatic::Option) << item elsif item.respond_to?(:options) += (item.) end end end end |
Instance Method Details
#to_hash ⇒ Hash
Returns Option data as a hash.
43 44 45 |
# File 'lib/translatomatic/option.rb', line 43 def to_hash @data end |