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
mod builder;
mod meta;

use crate::prelude::*;

pub use builder::*;
pub use meta::*;

/// Journal Entry
///
/// Represents a single markdown file created from a `Topic`
///
#[derive(Debug, Clone)]
pub struct Entry {
    /// Topic identifier to which this entry belongs
    topic: TopicName,
    /// Time this entry was created
    created_at: UtcDateTime,
    /// Location where this Entry is persisted to disk
    pub(crate) file_loc: Option<PathBuf>,
    /// Additional data found in the entries front-matter
    meta: EntryMeta,
    /// The contents of the markdown file except
    /// for the front-matter
    content: String,
}

impl Entry {
    pub(crate) fn builder<S>(topic: S) -> EntryBuilder
    where
        S: Into<TopicName>,
    {
        EntryBuilder::new(topic)
    }

    pub fn created_at(&self) -> &UtcDateTime {
        &self.created_at
    }

    pub fn meta(&self) -> &EntryMeta {
        &self.meta
    }

    pub fn meta_value<K>(&self, key: &K) -> Option<&MetaValue>
    where
        K: AsRef<str>,
    {
        self.meta.get(key)
    }

    pub fn topic_name(&self) -> &str {
        self.topic.as_ref()
    }

    pub fn content(&self) -> &str {
        &self.content
    }

    pub fn file_location(&self) -> Option<&PathBuf> {
        self.file_loc.as_ref()
    }
}