Sha256: c53f5505dd579b60f7219e8946c9973c8e6b8dcf7ba7511a078988b3761e0964

Contents?: true

Size: 985 Bytes

Versions: 230

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/struct'

module EacCli
  class Parser
    class Collector
      class << self
        def to_data(definition)
          collector = new(definition)
          yield(collector)
          collector.to_data
        end
      end

      common_constructor :definition do
        default_values
      end

      # @return [OpenStruct]
      def to_data
        ::EacRubyUtils::Struct.new(data.transform_keys(&:identifier))
      end

      def collect(option, value)
        data[option] = option.build_value(value, data[option])
      end

      def supplied?(option)
        data[option].present?
      end

      private

      def data
        @data ||= {}
      end

      def default_values
        definition.options.each { |option| data[option] = option.default_value }
        definition.positional.each { |positional| data[positional] = positional.default_value }
      end
    end
  end
end

Version data entries

230 entries across 230 versions & 4 rubygems

Version Path
eac_tools-0.40.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.39.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.38.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.37.2 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.37.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.37.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.36.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.36.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.35.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.34.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.33.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.32.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.31.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.31.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_cli-0.28.0 lib/eac_cli/parser/collector.rb
eac_tools-0.30.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.29.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.28.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.27.2 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.27.1 sub/eac_cli/lib/eac_cli/parser/collector.rb