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.81.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_cli-0.38.0 lib/eac_cli/parser/collector.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.76.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_cli-0.37.0 lib/eac_cli/parser/collector.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.74.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_cli-0.36.0 lib/eac_cli/parser/collector.rb
eac_tools-0.73.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.72.0 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.70.1 sub/eac_cli/lib/eac_cli/parser/collector.rb
eac_tools-0.70.0 sub/eac_cli/lib/eac_cli/parser/collector.rb