-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antonis Lilis
committed
Feb 21, 2019
1 parent
4ddb30d
commit 967a1db
Showing
8 changed files
with
590 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.code.style=official |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rootProject.name = 'json-logic-kotlin' | ||
|
Oops, something went wrong.