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; import com.camilstaps.common.DatedString; /** * Created by camilstaps on 7-4-15. */ public class DailyReading extends DatedString { public DailyReading(Date date, String string) { super(date, string); } public String getTextWithoutReference() { Matcher bible_ref_m = referenceMatcher(); if (bible_ref_m.find()) { return string.substring(0, bible_ref_m.start() - 1); } else { return string; } } 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(string); } public static DailyReading fromString(String s) throws JSONException, ParseException { return (DailyReading) DatedString.fromString(s, DailyReading.class); } }