<commit_before>#
#       ActiveFacts Ruby API Generator
#
# Copyright (c) 2009-2016 <NAME>. Read the LICENSE file.
#
require 'activefacts/metamodel'
require 'activefacts/compositions'
require 'activefacts/generator'
require 'activefacts/generator/oo'

module ActiveFacts
  module Generators
    # Options are comma or space separated:
    class Ruby < ObjectOriented
      def self.options
        super.merge(
          {
            scope: [String, "Generate a Ruby module that's nested inside the module you name here"]
          }
        )
      end

      def initialize composition, options = {}
        super
        @scope = options.delete('scope') || ''
        @scope = @scope.split(/::/)
        @scope_prefix = '  '*@scope.size
      end

      def prelude composition
        "require 'activefacts/api'\n\n" +
        (0...@scope.size).map{|i| '  '*i + "module #{@scope[i]}\n"}*'' +
        "#{@scope_prefix}module #{composition.name}\n"
      end

      def finale
        @scope.size.downto(0).map{|i| '  '*i+"end\n"}*''
      end

      def generate_classes composites
        super(composites).
          gsub(/^/, '  '*@scope.size)
      end

      def identified_by_roles identifying_roles
        "    identified_by   #{ identifying_roles.map{|m| ':'+ruby_role_name(m) }*', ' }\n"
      end

      def value_type_declaration object_type
        "    value_type#{object_type.length ? "      length: #{object_type.length}" : ''}\n"    # REVISIT: Add other parameters and value restrictions<commit_msg>Ensure that the module name is correct for a Ruby constant<commit_after>#
#       ActiveFacts Ruby API Generator
#
# Copyright (c) 2009-2016 <NAME>. Read the LICENSE file.
#
require 'activefacts/metamodel'
require 'activefacts/compositions'
require 'activefacts/generator'
require 'activefacts/generator/oo'

module ActiveFacts
  module Generators
    # Options are comma or space separated:
    class Ruby < ObjectOriented
      def self.options
        super.merge(
          {
            scope: [String, "Generate a Ruby module that's nested inside the module you name here"]
          }
        )
      end

      def initialize composition, options = {}
        super
        @scope = options.delete('scope') || ''
        @scope = @scope.split(/::/)
        @scope_prefix = '  '*@scope.size
      end

      def prelude composition
        "require 'activefacts/api'\n\n" +
        (0...@scope.size).map{|i| '  '*i + "module #{@scope[i]}\n"}*'' +
        "#{@scope_prefix}module #{composition.name.words.capcase}\n"
      end

      def finale
        @scope.size.downto(0).map{|i| '  '*i+"end\n"}*''
      end

      def generate_classes composites
        super(composites).
          gsub(/^/, '  '*@scope.size)
      end

      def identified_by_roles identifying_roles
        "    identified_by   #{ identifying_roles.map{|m| ':'+ruby_role_name(m) }*', ' }\n"
      end

      def value_type_declaration object_type
        "    value_type#{object_type.length ? "      length: #{object_type.length}" : ''}\n"    # REVISIT: Add other parameters and value restrictions
{'fraction_non_alphanumeric': 0.12907389480477574, 'fraction_numerical': 0.006453694740238786, 'mean_word_length': 2.4178610804851157, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4990689', 'n_tokens_mistral': 995, 'n_tokens_neox': 935, 'n_words': 229}