Sha256: 08d50dd0134e4d7d21eb6a800f005fca17ca6506bee8abc15218d33ba2ab8ba2
Contents?: true
Size: 1.36 KB
Versions: 8
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true module Lino module Model class Option attr_reader :option, :value, :separator, :quoting, :placement def initialize(option, value, opts = {}) opts = with_defaults(opts) @option = option @value = value @separator = opts[:separator] @quoting = opts[:quoting] @placement = opts[:placement] end def quoted_value "#{quoting}#{value}#{quoting}" end def string "#{option}#{separator}#{quoted_value}" end alias to_s string def array if separator == ' ' [option.to_s, value.to_s] else ["#{option}#{separator}#{value}"] end end alias to_a array def ==(other) self.class == other.class && state == other.state end alias eql? == def hash [self.class, state].hash end protected def state [ @option, @value, @separator, @quoting, @placement ] end private def with_defaults(opts) { separator: opts[:separator] || ' ', quoting: opts[:quoting], placement: opts[:placement] || :after_command } end end end end
Version data entries
8 entries across 8 versions & 1 rubygems