Skip to content

Commit

Permalink
First Public Version (0.9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Feb 21, 2019
1 parent 4ddb30d commit 967a1db
Show file tree
Hide file tree
Showing 8 changed files with 590 additions and 31 deletions.
29 changes: 6 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/*
.gradle/*
gradle/*
gradlew*
out/
build/*
75 changes: 67 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,82 @@
# json-logic-kotlin
[ ![Download](https://api.bintray.com/packages/advantagefse/json-logic-kotlin/eu.afse.jsonlogic/images/download.svg?version=0.9) ](https://bintray.com/advantagefse/json-logic-kotlin/eu.afse.jsonlogic/0.9/link)

This is a pure Kotlin implementation of JsonLogic http://jsonlogic.com rule engine. JsonLogic is documented extensively at [JsonLogic.com](http://jsonlogic.com), including examples of every [supported operation](http://jsonlogic.com/operations.html).

## Instalation
## Installation

TODO
```groovy
implementation 'eu.afse:eu.afse.jsonlogic:0.9'
```

## Examples

TODO
Typically jsonLogic will be called with a rule object and optionally a data object. Both rules and data input are JSON formatted strings.

## Compatibility
### Simple

This implementation is as close as it gets to the [JS implementation](https://github.com/jwadhams/json-logic-js/) and passes all the official [Unit Tests](http://jsonlogic.com/tests.json).
This is a simple test, equivalent to 1 == 1

```kotlin
JsonLogic().apply("{\"==\":[1,1]}")
//true
```

### Compound

An example with nested rules
```kotlin
val jsonLogic = JsonLogic()
jsonLogic.apply(
"{\"and\" : [" +
" { \">\" : [3,1] }," +
" { \"<\" : [1,3] }" +
"] }"
)
//true
```

### Data-Driven

You can use the var operator to get attributes of the data object

## Customization
```kotlin
val jsonLogic = JsonLogic()
val result = jsonLogic.apply(
"{ \"var\" : [\"a\"] }", // Rule
"{ a : 1, b : 2 }" // Data
)
//1
```

You can also use the var operator to access an array by numeric index

```kotlin
JsonLogic().apply(
"{\"var\" : 1 }", // Rule
"[ \"apple\", \"banana\", \"carrot\" ]" // Data
)
//banana
```

### Customization

[Adding custom operations](http://jsonlogic.com/add_operation.html) is also supported.

### Examples
```kotlin
val jsonLogic = JsonLogic()
jsonLogic.addOperation("sqrt") { l, _ ->
try {
if (l != null && l.size > 0) Math.sqrt(l[0].toString().toDouble())
else null
} catch (e: Exception) {
null
}
}
jsonLogic.apply("{\"sqrt\":\"9\"}")
//3
```

TODO
## Compatibility

This implementation is as close as it gets to the [JS implementation](https://github.com/jwadhams/json-logic-js/) and passes all the official [Unit Tests](http://jsonlogic.com/tests.json).
76 changes: 76 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
id "com.jfrog.bintray" version "1.8.4"
}

apply plugin: 'maven-publish'

group 'eu.afse'
version '0.9'

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation 'com.google.code.gson:gson:2.8.5'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

bintray {
user = 'user'
key = 'key'
publications = ['mavenJava']

pkg {
repo = 'json-logic-kotlin'
name = 'eu.afse.jsonlogic'
userOrg = 'advantagefse'
licenses = ['MIT']
vcsUrl = 'https://github.com/advantagefse/json-logic-kotlin'

version {
name = project.version
released = new Date()
vcsTag = "v${project.version}"
}
}
}

task sourcesJar(type: Jar, dependsOn: project.classes) {
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: project.javadoc) {
from javadoc.destinationDir
}

artifacts {
archives sourcesJar, javadocJar
}

publishing {
publications {
mavenJava(MavenPublication) {
artifactId project.bintray.pkg.name
from components.java

artifact sourcesJar {
classifier = 'sources'
}
artifact javadocJar {
classifier = 'javadoc'
}
}
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'json-logic-kotlin'

Loading

0 comments on commit 967a1db

Please sign in to comment.