Class: Pomodoro::Formats::Review::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/pomodoro/formats/review/section.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header:, raw_data:) ⇒ Section

Returns a new instance of Section.

Raises:

  • (ArgumentError)

13
14
15
16
17
# File 'lib/pomodoro/formats/review/section.rb', line 13

def initialize(header:, raw_data:)
  @header, @raw_data = header, raw_data

  raise ArgumentError unless header.is_a?(String)
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header


12
13
14
# File 'lib/pomodoro/formats/review/section.rb', line 12

def header
  @header
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data


12
13
14
# File 'lib/pomodoro/formats/review/section.rb', line 12

def raw_data
  @raw_data
end

Class Method Details

.pluginsObject


4
5
6
# File 'lib/pomodoro/formats/review/section.rb', line 4

def self.plugins
  @plugins ||= Array.new
end

.register(plugin) ⇒ Object


8
9
10
# File 'lib/pomodoro/formats/review/section.rb', line 8

def self.register(plugin)
  self.plugins << plugin
end

Instance Method Details

#dataObject


29
30
31
32
33
34
35
36
37
# File 'lib/pomodoro/formats/review/section.rb', line 29

def data
  if self.plugin && self.raw_data.empty?
    Array.new
  elsif self.plugin
    self.plugin.parse("#{self.raw_data}\n")
  else
    self.raw_data
  end
end

#method_nameObject


19
20
21
# File 'lib/pomodoro/formats/review/section.rb', line 19

def method_name
  @header.downcase.tr(' ', '_').to_sym
end

#pluginObject


23
24
25
26
27
# File 'lib/pomodoro/formats/review/section.rb', line 23

def plugin
  self.class.plugins.find do |plugin|
    self.header.match(plugin::HEADER)
  end
end