import { CaseStyle } from "./Casing/CaseStyle" ; import { Import } from "./Imports/Import" ; import { ImportRelativity } from "./Imports/ImportRelativity" ; import { Language } from "./Language" ; import { GeneralProperties } from "./Properties/GeneralProperties" ; import { ProjectProperties } from "./Properties/ProjectProperties" ; import { ArrayNewSizedSyntax } from "./Properties/Syntax/ArrayNewSizedSyntax" ; import { ArraySyntax } from "./Properties/Syntax/ArraySyntax" ; import { BooleanSyntax } from "./Properties/Syntax/BooleanSyntax" ; import { ClassGenericSyntax } from "./Properties/Syntax/ClassGenericSyntax" ; import { ClassMemberFunctionSyntax } from "./Properties/Syntax/ClassMemberFunctionSyntax" ; import { ClassMemberVariableSyntax } from "./Properties/Syntax/ClassMemberVariableSyntax" ; import { ClassStaticFunctionSyntax } from "./Properties/Syntax/ClassStaticFunctionSyntax" ; import { ClassStaticVariableSyntax } from "./Properties/Syntax/ClassStaticVariableSyntax" ; import { ClassSyntax } from "./Properties/Syntax/ClassSyntax" ; import { CommentSyntax } from "./Properties/Syntax/CommentSyntax" ; import { ConditionalSyntax } from "./Properties/Syntax/ConditionalSyntax" ; import { DictionarySyntax } from "./Properties/Syntax/DictionarySyntax" ; import { EnumSyntax } from "./Properties/Syntax/EnumSyntax" ; import { ExceptionSyntax } from "./Properties/Syntax/ExceptionSyntax" ; import { ExportSyntax } from "./Properties/Syntax/ExportSyntax" ; import { FileSyntax } from "./Properties/Syntax/FileSyntax" ; import { FunctionSyntax } from "./Properties/Syntax/FunctionSyntax" ; import { ImportSyntax } from "./Properties/Syntax/ImportSyntax" ; import { InterfaceSyntax } from "./Properties/Syntax/InterfaceSyntax" ; import { LambdaSyntax } from "./Properties/Syntax/LambdaSyntax" ; import { LambdaTypeInlineSyntax } from "./Properties/Syntax/LambdaTypeInlineSyntax" ; import { ListNewItemsSyntax } from "./Properties/Syntax/ListNewItemsSyntax" ; import { ListNewSizedSyntax } from "./Properties/Syntax/ListNewSizedSyntax" ; import { ListSliceSupport , ListSliceSyntax } from "./Properties/Syntax/ListSliceSyntax" ; import { ListSortMembersSyntax , ListSortMemberType } from "./Properties/Syntax/ListSortMembersSyntax" ; import { ListSyntax } from "./Properties/Syntax/ListSyntax" ; import { LoopSyntax } from "./Properties/Syntax/LoopSyntax" ; import { MainSyntax } from "./Properties/Syntax/MainSyntax" ; import { MathSyntax } from "./Properties/Syntax/MathSyntax" ; import { NativeCallScope , NativeCallSyntax , NativeCallType } from "./Properties/Syntax/NativeCallSyntax" ; import { NewInstantiationSyntaxKind , NewSyntax } from "./Properties/Syntax/NewSyntax" ; import { OperatorSyntax } from "./Properties/Syntax/OperatorSyntax" ; import { ParameterSyntax } from "./Properties/Syntax/ParameterSyntax" ; import { PrintingSyntax } from "./Properties/Syntax/PrintingSyntax" ; import { SetSyntax } from "./Properties/Syntax/SetSyntax" ; import { StandaloneFunctionSyntax } from "./Properties/Syntax/StandaloneFunctionSyntax" ; import { StringFormatSyntax } from "./Properties/Syntax/StringFormatSyntax" ; import { StringSubstringSupport , StringSubstringSyntax } from "./Properties/Syntax/StringSubstringSyntax" ; import { StringSyntax } from "./Properties/Syntax/StringSyntax" ; import { StringToNumberStartConversionType , StringToNumberSyntax } from "./Properties/Syntax/StringToNumberSyntax" ; import { StyleSyntax } from "./Properties/Syntax/StyleSyntax" ; import { UnsupportedSyntax } from "./Properties/Syntax/UnsupportedSyntax" ; import { VariableSyntax } from "./Properties/Syntax/VariableSyntax" ; /**
 * A summary of information for the Ruby language.
 */ export class Ruby extends Language { param general protected generateGeneralProperties ( general ) { general . directoryCase = CaseStyle . SnakeCase ; general . extension = ".rb" ; general . fileCase = CaseStyle . SnakeCase ; general . name = "Ruby" ; } param projects protected generateProjectProperties ( projects ) { projects . mainFile = "main.rb" ; projects . metadataFiles = { Gemfile : [ `source "https://rubygems.org"` , `` , `gemspec` ] , "{name}.gemspec" : [ `# encoding: utf-8` , `` , `Gem::Specification.new do |spec|` , `    spec.author = ["{author}"]` , `    spec.description = "{description}"` , `    spec.email = "{email}"` , `    spec.files = Dir[` , `        *.md,` , `        {{#exports}},` , `        {file}` , `        {{/exports}},` , `    ]` , `    spec.homepage = "{homepage}"` , `    spec.license = "{license}"` , `    spec.name = "{name}"` , `    spec.summary = spec.description` , `    spec.version = "{version}"` , `` , ] , } ; projects . nameFormat = CaseStyle . DashLowerCase ; } param generics protected generateClassGenericSyntax ( generics ) { } param arrays protected generateArraySyntax ( arrays ) { arrays . className = "Array" ; arrays . length = new NativeCallSyntax ( "length" , NativeCallScope . Member , NativeCallType . Property ) ; arrays . newGenericCastRequired = false ; arrays . requiredImports = [ ] ; } param arrays protected generateArrayNewSizedSyntax ( newSized ) { newSized . includeType = false ; newSized . left = "Array.new(" ; newSized . right = ")" ; } param booleans protected generateBooleanSyntax ( booleans ) { booleans . className = "" ; } param functions protected generateClassMemberFunctionSyntax ( functions ) { functions . includeThisReference = false ; functions . private = "def " ; functions . privateCase = CaseStyle . SnakeCase ; functions . privatePrefix = "" ; functions . protected = "def " ; functions . protectedCase = CaseStyle . SnakeCase ; functions . protectedPrefix = "" ; functions . public = "def " ; functions . publicCase = CaseStyle . SnakeCase ; functions . publicPrefix = "" ; } param members protected generateClassMemberVariableSyntax ( variables ) { variables . publicPrefix = "" ; variables . skipMemberVariables = false ; variables . private = "attr_accessor :" ; variables . privateCase = CaseStyle . CamelCase ; variables . privatePrefix = "" ; variables . protected = "attr_accessor :" ; variables . protectedCase = CaseStyle . CamelCase ; variables . protectedPrefix = "" ; variables . public = "attr_accessor :" ; variables . publicCase = CaseStyle . CamelCase ; variables . publicPrefix = "" ; } param classes protected generateClassSyntax ( classes ) { classes . constructors . private = "" ; classes . constructors . protected = "" ; classes . constructors . public = "" ; classes . constructors . useKeyword = true ; classes . newStart = "new " ; classes . this = "self" ; classes . abstractDeclaration = "" ; classes . aliases = { char : "string" , dictionary : "Hash" , number : "Double" , } ; classes . constructors . baseConstructor = "super" ; classes . constructors . keyword = "def initialize" ; classes . constructors . takeThis = false ; classes . declareEnd = "end" ; classes . declareExtendsLeft = " < " ; classes . declareExtendsRight = "" ; classes . declareStartLeft = "class " ; classes . declareStartRight = "" ; classes . instanceOf = new NativeCallSyntax ( ".kind_of? " , NativeCallScope . Operator , NativeCallType . FloatingRight ) ; classes . statics . labelBeforePublicity = false ; } param functions protected generateClassStaticFunctionSyntax ( functions ) { functions . label = "self." ; functions . private = "def " ; functions . privateCase = CaseStyle . SnakeCase ; functions . privatePrefix = "" ; functions . protected = "def " ; functions . protectedCase = CaseStyle . SnakeCase ; functions . protectedPrefix = "" ; functions . public = "def " ; functions . publicCase = CaseStyle . SnakeCase ; functions . publicPrefix = "" ; } param members protected generateClassStaticVariableSyntax ( variables ) { variables . private = "" ; variables . protected = "" ; variables . public = "" ; variables . skipStaticVariables = true ; variables . label = "@@" ; variables . privateCase = CaseStyle . CamelCase ; variables . privatePrefix = "" ; variables . protectedCase = CaseStyle . CamelCase ; variables . protectedPrefix = "" ; variables . publicCase = CaseStyle . CamelCase ; variables . publicPrefix = "" ; } param comments protected generateCommentSyntax ( comments ) { comments . blockEnd = "=end" ; comments . blockLineLeft = "" ; comments . blockLineRight = "" ; comments . blockStart = "=begin" ; comments . docEnd = "##" ; comments . docLineEnd = "" ; comments . docLineStart = "# " ; comments . docStart = "##" ; comments . docTagAliases = { note : "remarks" , parameter : "\0" , returns : "returns" , summary : "" , todo : "todo" , } ; comments . docTagsWithParameters = { parameter : "" , } ; comments . docTagEnd = "] " ; comments . docTagSpaceAfter = "  " ; comments . docTagStart = "[" ; comments . lineLeft = "# " ; comments . lineRight = "" ; } param conditionals protected generateConditionalSyntax ( conditionals ) { conditionals . continueLeft = "" ; conditionals . else = "else" ; conditionals . end = "\0" ; conditionals . if = "if" ; conditionals . startLeft = " " ; conditionals . continueRight = "" ; conditionals . end = "end" ; conditionals . elif = "elsif" ; conditionals . startRight = "" ; } param dictionaries protected generateDictionarySyntax ( dictionaries ) { dictionaries . className = "hash" ; dictionaries . containsKey = new NativeCallSyntax ( "key?" , NativeCallScope . Member , NativeCallType . Function ) ; dictionaries . getLeft = "[" ; dictionaries . getRight = "]" ; dictionaries . initializeAsLiteral = "{}" ; dictionaries . initializeEnd = "}" ; dictionaries . initializePairComma = "," ; dictionaries . initializePairLeft = "" ; dictionaries . initializePairMiddle = " => " ; dictionaries . initializePairRight = "" ; dictionaries . initializeStart = "{" ; dictionaries . keys = new NativeCallSyntax ( "keys" , NativeCallScope . Member , NativeCallType . Property ) ; dictionaries . requiredImports = [ ] ; dictionaries . setLeft = "[" ; dictionaries . setMiddle = "] = " ; dictionaries . setRight = "" ; } param enums protected generateEnumSyntax ( enums ) { enums . declareCommaRight = "" ; enums . declareLastRight = "" ; enums . declareExternal = "class {0}" ; enums . declareInternal = "class {0}" ; enums . declareValueLeft = " = " ; enums . declareValueRight = "" ; enums . declareValues = true ; enums . isObject = false ; enums . requiredImports = [ ] ; enums . valueLeft = "" ; enums . valueMiddle = "::" ; enums . valueRight = "" ; } param exceptions protected generateExceptionSyntax ( exceptions ) { exceptions . blockEnd = "" ; exceptions . catch = "rescue" ; exceptions . catchStartLink = " => " ; exceptions . catchStartMiddle = " " ; exceptions . catchStartRight = "" ; exceptions . className = "Exception" ; exceptions . finally = "ensure" ; exceptions . finallyStartRight = "" ; exceptions . requiredImports = [ ] ; exceptions . requiresExceptionType = true ; exceptions . throw = "raise" ; exceptions . throwMiddle = ".new(" ; exceptions . throwRight = ")" ; exceptions . try = "begin" ; exceptions . tryStartRight = "" ; exceptions . variablePrefix = "" ; } param members protected generateExportSyntax ( exports ) { exports . exportedLeft = "" ; exports . internal = "" ; } param file protected generateFileSyntax ( files ) { files . endLines = [ ] ; files . indentation = 0 ; files . startCase = CaseStyle . FileSystemLowerCase ; files . startLines = [ ] ; } param functions protected generateFunctionSyntax ( functions ) { functions . case = CaseStyle . SnakeCase ; functions . defineStartLeft = "def " ; functions . requiresExceptions = false ; functions . defineStartRight = "" ; functions . defineEnd = "end" ; } param imports protected generateImportSyntax ( imports ) { imports . case = CaseStyle . DirectoryLowerCase ; imports . leftAbsolute = 'require "' ; imports . leftLocal = 'require_relative "' ; imports . right = '"' ; imports . transformFileNames = true ; imports . useLocalRelativeImports = true ; imports . useLocalRelativePaths = true ; } param interfaces protected generateInterfaceSyntax ( interfaces ) { interfaces . supported = false ; } param lambdas protected generateLambdaSyntax ( lambdas ) { lambdas . callLeft = ".call(" ; lambdas . callRight = ")" ; lambdas . functionLeft = "lambda { |" ; lambdas . functionMiddle = "| " ; lambdas . functionRight = " }" ; lambdas . parameterTypeRequired = false ; lambdas . returnTypeRequired = false ; } param typeInline protected generateLambdaTypeInlineSyntax ( typeInline ) { } param lists protected generateListSyntax ( lists ) { lists . addList = new NativeCallSyntax ( "concat" , NativeCallScope . Member , NativeCallType . Function ) ; lists . asArray = true ; lists . getLeft = "[" ; lists . getRight = "]" ; lists . insert = new NativeCallSyntax ( "insert" , NativeCallScope . Member , NativeCallType . Function ) ; lists . length = new NativeCallSyntax ( "length" , NativeCallScope . Member , NativeCallType . Property ) ; lists . pop = new NativeCallSyntax ( "pop" , NativeCallScope . Member , NativeCallType . Property ) ; lists . popFront = new NativeCallSyntax ( "shift" , NativeCallScope . Member , NativeCallType . Property ) ; lists . push = new NativeCallSyntax ( "push" , NativeCallScope . Member , NativeCallType . Function ) ; lists . requiredImports = [ ] ; lists . setLeft = "[" ; lists . setMiddle = "] = " ; lists . setRight = "" ; lists . sortNumbers = new NativeCallSyntax ( "sort!" , NativeCallScope . Member , NativeCallType . Function ) ; lists . sortStrings = lists . sortNumbers ; } /**
     * Fills out metadata on list creation with items.
     */ protected generateListNewItemsSyntax ( newItems ) { } param arrays protected generateListNewSizedSyntax ( newSized ) { newSized . includeType = false ; newSized . left = "Array.new(" ; newSized . right = ")" ; } /**
     * Fills out metadata on list slicing.
     */ protected generateListSliceSyntax ( slices ) { slices . before = "" ; slices . left = ".slice(" ; slices . middle = ", " ; slices . right = ")" ; slices . support = ListSliceSupport . Length ; slices . untilEndDefaultStart = "0" ; slices . untilEndLeft = ".slice(" ; slices . untilEndMiddle = "" ; slices . untilEndRightFromIndex = ")" ; slices . untilEndRightFromStart = ")" ; } /**
     * Fills out metadata on list sorting by keyed members.
     */ protected generateListSortMemberNumbersSyntax ( sortMembers ) { sortMembers . lambdaLeft = ".sort_by! {|" ; sortMembers . lambdaMiddleLeft = "| " ; sortMembers . lambdaRight = "}" ; sortMembers . requiredImports = [ ] ; sortMembers . type = ListSortMemberType . ShorthandLambda ; } /**
     * Fills out metadata on list sorting by keyed members.
     */ protected generateListSortMemberStringsSyntax ( sortMembers ) { sortMembers . lambdaLeft = ".sort_by! {|" ; sortMembers . lambdaMiddleLeft = "| " ; sortMembers . lambdaRight = "}" ; sortMembers . requiredImports = [ ] ; sortMembers . type = ListSortMemberType . ShorthandLambda ; } param loops protected generateLoopSyntax ( loops ) { loops . break = "break" ; loops . continue = "next" ; loops . for = "for" ; loops . forEachMiddle = " in " ; loops . forEachStartIteration = " " ; loops . rangedForLoops = true ; loops . whileStartLeft = "while" ; loops . whileStartMiddle = " " ; loops . whileStartRight = ":" ; loops . foreach = "foreach" ; loops . forEachAsMethod = true ; loops . forEachEnd = "end" ; loops . forEachKeyEnd = "}" ; loops . forEachGetKeys = ".each_key { |" ; loops . forEachGetPairs = ".each { |" ; loops . forEachPairEnd = "}" ; loops . forEachRight = "|" ; loops . forNumbersEnd = "end" ; loops . forEachStartLeft = "for" ; loops . forEachStartSeparator = " in " ; loops . forEachStartRight = "" ; loops . rangedForLoopsFunctionalIncrementor = true ; loops . rangedForLoopsFunctionalLeft = "(" ; loops . rangedForLoopsFunctionalMiddleLeft = "..." ; loops . rangedForLoopsFunctionalMiddleMiddle = ").step(" ; loops . rangedForLoopsFunctionalMiddleRight = ") do |" ; loops . rangedForLoopsFunctionalRight = "|" ; loops . rangedForLoopsLeft = " in " ; loops . rangedForLoopsMiddle = "..." ; loops . rangedForLoopsRight = "" ; loops . whileStartRight = "" ; } param math protected generateMainSyntax ( main ) { main . contextEndLines = [ ] ; main . contextIndentation = 0 ; main . contextStartLines = [ ] ; main . group = "" ; main . mainEndLines = [ ] ; main . mainIndentation = 0 ; main . mainStartLines = [ ] ; } param math protected generateMathSyntax ( math ) { math . absolute = new NativeCallSyntax ( "abs" , NativeCallScope . Member , NativeCallType . Property ) ; math . asInt = new NativeCallSyntax ( "floor" , NativeCallScope . Member , NativeCallType . Property ) ; math . ceiling = new NativeCallSyntax ( "ceil" , NativeCallScope . Member , NativeCallType . Property ) ; math . floor = new NativeCallSyntax ( "floor" , NativeCallScope . Member , NativeCallType . Property ) ; math . max = new NativeCallSyntax ( "max" , NativeCallScope . Array , NativeCallType . Function ) ; math . min = new NativeCallSyntax ( "min" , NativeCallScope . Array , NativeCallType . Function ) ; math . power = new NativeCallSyntax ( "pow" , NativeCallScope . Array , NativeCallType . Function ) ; math . mathName = "Math" ; } param newProp protected generateNewSyntax ( newProp ) { newProp . instantiationKind = NewInstantiationSyntaxKind . MemberMethodCall ; newProp . keyword = "new" ; } param operators protected generateOperatorSyntax ( operators ) { operators . and = "&&" ; operators . decreaseBy = "-=" ; operators . divide = "/" ; operators . divideBy = "/=" ; operators . equals = "=" ; operators . equalTo = "==" ; operators . greaterThan = ">" ; operators . greaterThanOrEqualTo = ">=" ; operators . increaseBy = "+=" ; operators . lessThan = "<" ; operators . lessThanOrEqualTo = "<=" ; operators . minus = "-" ; operators . mod = "%" ; operators . multiplyBy = "*=" ; operators . not = "!" ; operators . notEqualTo = "!=" ; operators . or = "||" ; operators . plus = "+" ; operators . times = "*" ; } param parameters protected generateParameterSyntax ( parameters ) { parameters . restDeclarationAfter = false ; parameters . restDeclarationType = false ; parameters . restKeywordLeft = "*" ; parameters . restKeywordMiddle = "" ; parameters . restKeywordRight = "" ; } param parameters protected generatePrintingSyntax ( printing ) { printing . end = "" ; printing . requiredImports = [ ] ; printing . start = "puts " ; } param parameters protected generateSetSyntax ( sets ) { sets . add = new NativeCallSyntax ( "add" , NativeCallScope . Member , NativeCallType . Function ) ; sets . className = "Set" ; sets . contains = new NativeCallSyntax ( "include?" , NativeCallScope . Member , NativeCallType . Function ) ; sets . initializeAsNew = false ; sets . initializeStart = "" ; sets . requiredImports = [ new Import ( [ "set" ] , [ "set" ] , ImportRelativity . Absolute ) ] ; sets . startItemsLeft = "([" ; sets . startItemsRight = "])" ; sets . startNoItems = ".new" ; sets . toArray = new NativeCallSyntax ( "to_a" , NativeCallScope . Member , NativeCallType . Function ) ; sets . toList = sets . toArray ; } param parameters protected generateStandaloneFunctionSyntax ( standaloneFunctions ) { standaloneFunctions . withinStaticClass = false ; } param strings protected generateStringFormatSyntax ( formatting ) { formatting . formatLeft = '"' ; formatting . formatMiddle = '" % [' ; formatting . formatAbbreviated = '" % [' ; formatting . formatRight = "]" ; formatting . formatInputLeft = "" ; formatting . formatInputRight = "" ; formatting . includeIndexInFormatting = false ; formatting . inputTypes = true ; formatting . useInterpolation = false ; formatting . typeCodes = { char : "%c" , double : "%f" , int : "%d" , string : "%s" , } ; } param strings protected generateStringSyntax ( strings ) { strings . caseLower = new NativeCallSyntax ( "downcase" , NativeCallScope . Member , NativeCallType . Property ) ; strings . caseUpper = new NativeCallSyntax ( "upcase" , NativeCallScope . Member , NativeCallType . Property ) ; strings . className = "string" ; strings . concatenate = " + " ; strings . indexLeft = "[" ; strings . indexOf = new NativeCallSyntax ( "index" , NativeCallScope . Member , NativeCallType . Function ) ; strings . indexOfNotFound = "nil" ; strings . indexRight = "]" ; strings . length = new NativeCallSyntax ( "length" , NativeCallScope . Member , NativeCallType . Property ) ; strings . trim = new NativeCallSyntax ( "strip" , NativeCallScope . Member , NativeCallType . Property ) ; } param strings protected generateStringSubstringSyntax ( substrings ) { substrings . defaultEnd = "..-1" ; substrings . leftIndex = "[" ; substrings . leftLength = "[" ; substrings . middle = ".." ; substrings . right = "]" ; substrings . support = StringSubstringSupport . Length ; } param toDouble protected generateStringToDoubleSyntax ( toDouble ) { toDouble . conversionType = StringToNumberStartConversionType . ConvertAndValidate ; toDouble . perVariableConversionStartLeft = "" ; toDouble . perVariableConversionStartMiddle = " = Float(" ; toDouble . perVariableConversionStartRight = ") rescue nil\n" ; toDouble . validationBlockComparison = "{1} != nil" ; toDouble . validationBlockLeft = "\nif (" ; toDouble . validationBlockMiddle = " && " ; toDouble . validationBlockRight = ")" ; } param toInt protected generateStringToIntSyntax ( toInt ) { toInt . conversionType = StringToNumberStartConversionType . ConvertAndValidate ; toInt . perVariableConversionStartLeft = "" ; toInt . perVariableConversionStartMiddle = " = Float(" ; toInt . perVariableConversionStartRight = ") rescue nil\n" ; toInt . validationBlockComparison = "{1} != nil" ; toInt . validationBlockLeft = "\nif (" ; toInt . validationBlockMiddle = " && " ; toInt . validationBlockRight = ")" ; } param style protected generateStyleSyntax ( style ) { style . semicolon = "" ; } param style protected generateUnsupportedSyntax ( unsupported ) { unsupported . complaintEnd = "=begin\n" ; unsupported . complaintStart = "\nend" ; } param variables protected generateVariableSyntax ( variables ) { variables . declaration = "" ; variables . aliases = { infinity : "double::Infinity" , } ; variables . null = "Nil" ; variables . isNullLeft = "" ; variables . isNullMiddle = "" ; variables . isNotNullLeft = "!" ; variables . isNotNullMiddle = "" ; variables . nullRight = ".nil?" ; } }