Class: Zettel::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/zettel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(note, filename = nil) ⇒ Note

Returns a new instance of Note.



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
# File 'lib/zettel.rb', line 6

def initialize(note, filename = nil)
  @raw_body = note

  @frontmatter, body = extract_frontmatter(note)
  title, @body = body.split("\n", 2).map(&:strip)
  @title = title.gsub('#', '').strip
  # @title = extract_title(body)

  @filename = filename
  if filename
    @extension = File.extname(filename)
    @identificator, @title = filename.gsub(/#{@extension}$/, '').split(" ", 2)
    @title = @title&.unicode_normalize || ""
    id_parts = @identificator.split('.')
    raise "Strange id - has more than two parts: #{id_parts}" if id_parts.size > 2

    @timestamp, @ordering = id_parts.reverse

    @ordering =~ /(\d+)([a-z\d]+)?/
    @leading_number = $1
    @following_number = $2

    @timestamp, @temporary_sign = @timestamp.split('_').reverse
    @time = created_at(@timestamp)
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/zettel.rb', line 5

def body
  @body
end

#frontmatterObject (readonly)

Returns the value of attribute frontmatter.



5
6
7
# File 'lib/zettel.rb', line 5

def frontmatter
  @frontmatter
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/zettel.rb', line 5

def time
  @time
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/zettel.rb', line 5

def title
  @title
end