Class: Hefted::Argument
- Inherits:
-
Object
- Object
- Hefted::Argument
- Defined in:
- lib/hefted/argument.rb
Instance Method Summary collapse
-
#initialize(**args) ⇒ Argument
constructor
A new instance of Argument.
- #join? ⇒ Boolean
- #joins ⇒ Object
- #keys ⇒ Object
- #name ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(**args) ⇒ Argument
Returns a new instance of Argument.
8 9 10 11 12 13 |
# File 'lib/hefted/argument.rb', line 8 def initialize(**args) @name = args.fetch(:name) @join = args.fetch(:join, nil) @first = args.indexer!(:first)[:first] @members = args[:members] || args.select { |key, value| !%i(name join).include?(key) } end |
Instance Method Details
#join? ⇒ Boolean
43 44 45 |
# File 'lib/hefted/argument.rb', line 43 def join? !!@join end |
#joins ⇒ Object
47 48 49 |
# File 'lib/hefted/argument.rb', line 47 def joins @join.map { |name| name.to_camel } end |
#keys ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hefted/argument.rb', line 19 def keys case @members when Array raise MissingKeysError if @members.include?(nil) @members when Hash @members.keys else raise MissingKeysError end.map(&:to_sym) end |
#name ⇒ Object
15 16 17 |
# File 'lib/hefted/argument.rb', line 15 def name @name.to_camel end |
#values ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hefted/argument.rb', line 31 def values case @members when Array @members.map.with_index(@first) { |key, i| i } when Hash raise MissingValuesError if @members.has_value?(nil) @members.values else raise MissingValuesError end end |