blob: 71c38acab43cf771f014c7c5e3b92cbea7f40e3a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package com.camilstaps.taize;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.camilstaps.common.Date;
/**
* Created by camilstaps on 7-4-15.
*/
public class DailyReading {
private final Date date;
private final String text;
public DailyReading(Date date, String text) {
this.date = date;
this.text = text;
}
public String getText() {
return text;
}
public Date getDate() {
return date;
}
public String getTextWithoutReference() {
Matcher bible_ref_m = referenceMatcher();
if (bible_ref_m.find()) {
return text.substring(0, bible_ref_m.start() - 1);
} else {
return text;
}
}
@Override
public String toString() {
JSONObject json = new JSONObject();
try {
json.put("date", date.toString());
json.put("text", text);
} catch (JSONException e) {}
return json.toString();
}
public static DailyReading fromString(String s) throws JSONException, ParseException {
JSONObject json = new JSONObject(s);
return new DailyReading(new Date(json.getString("date")), json.getString("text"));
}
public BibleText getBibleReference() {
final Matcher bible_ref_m = referenceMatcher();
if (!bible_ref_m.find()) {
return null;
}
return new BibleText(bible_ref_m.group(1), Integer.parseInt(bible_ref_m.group(2)), Integer.parseInt(bible_ref_m.group(3)), Integer.parseInt(bible_ref_m.group(2)), Integer.parseInt(bible_ref_m.group(4)));
}
private Matcher referenceMatcher() {
Pattern bible_ref = Pattern.compile("\\((\\d? ?[a-zA-Z]+) (\\d{1,2})(?::|,)(\\d+)-?(\\d+?)\\)");
return bible_ref.matcher(text);
}
}
|