Class: Lino::Model::Subcommand

Inherits:
Object
  • Object
show all
Defined in:
lib/lino/model/subcommand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subcommand, opts = {}) ⇒ Subcommand

Returns a new instance of Subcommand.



8
9
10
11
12
# File 'lib/lino/model/subcommand.rb', line 8

def initialize(subcommand, opts = {})
  opts = with_defaults(opts)
  @subcommand = subcommand
  @options = Hamster::Vector.new(opts[:options])
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/lino/model/subcommand.rb', line 6

def options
  @options
end

#subcommandObject (readonly)

Returns the value of attribute subcommand.



6
7
8
# File 'lib/lino/model/subcommand.rb', line 6

def subcommand
  @subcommand
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



24
25
26
27
# File 'lib/lino/model/subcommand.rb', line 24

def ==(other)
  self.class == other.class &&
    state == other.state
end

#arrayObject Also known as: to_a



19
20
21
# File 'lib/lino/model/subcommand.rb', line 19

def array
  [@subcommand.to_s, @options.map(&:array)].flatten
end

#hashObject



30
31
32
# File 'lib/lino/model/subcommand.rb', line 30

def hash
  [self.class, state].hash
end

#stringObject Also known as: to_s



14
15
16
# File 'lib/lino/model/subcommand.rb', line 14

def string
  [@subcommand.to_s, @options.map(&:string)].reject(&:empty?).join(' ')
end