Sha256: 0ae327cd89184945492611fae58c3480c7930832126e24a91e0a785ca9c54a2c

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require_relative 'utilities'

module Lino
  module Options
    include Lino::Utilities

    def with_option(
      option,
      value,
      separator: nil,
      quoting: nil,
      placement: nil
    )
      return self if missing?(value)

      with(options: @options.add(
        {
          components: [option, value],
          separator: separator,
          quoting: quoting,
          placement: placement
        }
      ))
    end

    def with_options(options)
      return self if missing?(options)

      options.entries.inject(self) do |s, entry|
        s.with_option(
          or_nth(entry, :option, 0),
          or_nth(entry, :value, 1),
          separator: or_nil(entry, :separator),
          quoting: or_nil(entry, :quoting),
          placement: or_nil(entry, :placement)
        )
      end
    end

    def with_repeated_option(
      option,
      values,
      separator: nil,
      quoting: nil,
      placement: nil
    )
      values.inject(self) do |s, value|
        s.with_option(
          option,
          value,
          separator: separator,
          quoting: quoting,
          placement: placement
        )
      end
    end

    def with_flag(flag)
      return self if missing?(flag)

      with(options: @options.add({ components: [flag] }))
    end

    def with_flags(flags)
      return self if missing?(flags)

      flags.inject(self) { |s, flag| s.with_flag(flag) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lino-2.7.0 lib/lino/options.rb
lino-2.6.0.pre.3 lib/lino/options.rb
lino-2.6.0.pre.2 lib/lino/options.rb