Class: GDK::Announcement

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

Constant Summary collapse

VALID_FILENAME_REGEX =
/\A\d{4}_\w+\.yml/
FilenameInvalidError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath, header, body) ⇒ Announcement

Returns a new instance of Announcement.



18
19
20
21
22
23
24
25
# File 'lib/gdk/announcement.rb', line 18

def initialize(filepath, header, body)
  @filepath = Pathname.new(filepath)
  raise FilenameInvalidError unless filename_valid?

  @header = header
  @body = body
  read_cache_file_contents!
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/gdk/announcement.rb', line 9

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



9
10
11
# File 'lib/gdk/announcement.rb', line 9

def header
  @header
end

Class Method Details

.from_file(filepath) ⇒ Object



13
14
15
16
# File 'lib/gdk/announcement.rb', line 13

def self.from_file(filepath)
  yaml = YAML.safe_load(filepath.read)
  new(filepath, yaml['header'], yaml['body'])
end

Instance Method Details

#renderObject



31
32
33
34
35
36
# File 'lib/gdk/announcement.rb', line 31

def render
  return unless render?

  display
  cache_announcement_rendered
end

#render?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/gdk/announcement.rb', line 27

def render?
  cache_file_contents[announcement_unique_identifier] != true
end