Skip to content

Commit 967a1db

Browse files
author
Antonis Lilis
committed
First Public Version (0.9)
1 parent 4ddb30d commit 967a1db

File tree

8 files changed

+590
-31
lines changed

8 files changed

+590
-31
lines changed

.gitignore

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
# Compiled class file
2-
*.class
3-
4-
# Log file
5-
*.log
6-
7-
# BlueJ files
8-
*.ctxt
9-
10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
12-
13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
21-
22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
1+
.idea/*
2+
.gradle/*
3+
gradle/*
4+
gradlew*
5+
out/
6+
build/*

README.md

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,82 @@
11
# json-logic-kotlin
2+
[ ![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)
23

34
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).
45

5-
## Instalation
6+
## Installation
67

7-
TODO
8+
```groovy
9+
implementation 'eu.afse:eu.afse.jsonlogic:0.9'
10+
```
811

912
## Examples
1013

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

13-
## Compatibility
16+
### Simple
1417

15-
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).
18+
This is a simple test, equivalent to 1 == 1
19+
20+
```kotlin
21+
JsonLogic().apply("{\"==\":[1,1]}")
22+
//true
23+
```
24+
25+
### Compound
26+
27+
An example with nested rules
28+
```kotlin
29+
val jsonLogic = JsonLogic()
30+
jsonLogic.apply(
31+
"{\"and\" : [" +
32+
" { \">\" : [3,1] }," +
33+
" { \"<\" : [1,3] }" +
34+
"] }"
35+
)
36+
//true
37+
```
38+
39+
### Data-Driven
40+
41+
You can use the var operator to get attributes of the data object
1642

17-
## Customization
43+
```kotlin
44+
val jsonLogic = JsonLogic()
45+
val result = jsonLogic.apply(
46+
"{ \"var\" : [\"a\"] }", // Rule
47+
"{ a : 1, b : 2 }" // Data
48+
)
49+
//1
50+
```
51+
52+
You can also use the var operator to access an array by numeric index
53+
54+
```kotlin
55+
JsonLogic().apply(
56+
"{\"var\" : 1 }", // Rule
57+
"[ \"apple\", \"banana\", \"carrot\" ]" // Data
58+
)
59+
//banana
60+
```
61+
62+
### Customization
1863

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

21-
### Examples
66+
```kotlin
67+
val jsonLogic = JsonLogic()
68+
jsonLogic.addOperation("sqrt") { l, _ ->
69+
try {
70+
if (l != null && l.size > 0) Math.sqrt(l[0].toString().toDouble())
71+
else null
72+
} catch (e: Exception) {
73+
null
74+
}
75+
}
76+
jsonLogic.apply("{\"sqrt\":\"9\"}")
77+
//3
78+
```
2279

23-
TODO
80+
## Compatibility
81+
82+
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).

build.gradle

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
3+
id "com.jfrog.bintray" version "1.8.4"
4+
}
5+
6+
apply plugin: 'maven-publish'
7+
8+
group 'eu.afse'
9+
version '0.9'
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
17+
implementation 'com.google.code.gson:gson:2.8.5'
18+
19+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
20+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
21+
}
22+
23+
compileKotlin {
24+
kotlinOptions.jvmTarget = "1.8"
25+
}
26+
compileTestKotlin {
27+
kotlinOptions.jvmTarget = "1.8"
28+
}
29+
30+
bintray {
31+
user = 'user'
32+
key = 'key'
33+
publications = ['mavenJava']
34+
35+
pkg {
36+
repo = 'json-logic-kotlin'
37+
name = 'eu.afse.jsonlogic'
38+
userOrg = 'advantagefse'
39+
licenses = ['MIT']
40+
vcsUrl = 'https://github.com/advantagefse/json-logic-kotlin'
41+
42+
version {
43+
name = project.version
44+
released = new Date()
45+
vcsTag = "v${project.version}"
46+
}
47+
}
48+
}
49+
50+
task sourcesJar(type: Jar, dependsOn: project.classes) {
51+
from sourceSets.main.allSource
52+
}
53+
54+
task javadocJar(type: Jar, dependsOn: project.javadoc) {
55+
from javadoc.destinationDir
56+
}
57+
58+
artifacts {
59+
archives sourcesJar, javadocJar
60+
}
61+
62+
publishing {
63+
publications {
64+
mavenJava(MavenPublication) {
65+
artifactId project.bintray.pkg.name
66+
from components.java
67+
68+
artifact sourcesJar {
69+
classifier = 'sources'
70+
}
71+
artifact javadocJar {
72+
classifier = 'javadoc'
73+
}
74+
}
75+
}
76+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'json-logic-kotlin'
2+

0 commit comments

Comments
 (0)