Class: Lino::Model::Option

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option, value, opts = {}) ⇒ Option

Returns a new instance of Option.



12
13
14
15
16
17
18
19
# File 'lib/lino/model/option.rb', line 12

def initialize(option, value, opts = {})
  opts = with_defaults(opts)
  @option = option
  @value = value
  @separator = opts[:separator]
  @quoting = opts[:quoting]
  @placement = opts[:placement]
end

Instance Attribute Details

#optionObject (readonly)

Returns the value of attribute option.



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

def option
  @option
end

#placementObject (readonly)

Returns the value of attribute placement.



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

def placement
  @placement
end

#quotingObject (readonly)

Returns the value of attribute quoting.



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

def quoting
  @quoting
end

#separatorObject (readonly)

Returns the value of attribute separator.



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

def separator
  @separator
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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



39
40
41
42
# File 'lib/lino/model/option.rb', line 39

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

#arrayObject Also known as: to_a



30
31
32
33
34
35
36
# File 'lib/lino/model/option.rb', line 30

def array
  if separator == ' '
    [option.to_s, value.to_s]
  else
    ["#{option}#{separator}#{value}"]
  end
end

#hashObject



46
47
48
# File 'lib/lino/model/option.rb', line 46

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

#quoted_valueObject



21
22
23
# File 'lib/lino/model/option.rb', line 21

def quoted_value
  "#{quoting}#{value}#{quoting}"
end

#stringObject Also known as: to_s



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

def string
  "#{option}#{separator}#{quoted_value}"
end