Class: Rubyfocus::ReviewPeriod

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

Overview

The ReviewPeriod represents a review period used with Projects in OmniFocus The ReviewPeriod is made up of three sections:

  • The precursor symbol (~ or @, use unknown)

  • A numerical “size”

  • A unit ([d]ays, [w]eeks, [m]onths or [y]ears)

Constant Summary collapse

ALLOWED_UNITS =
%i(days weeks months years)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size: 0, unit: :months) ⇒ ReviewPeriod

Returns a new instance of ReviewPeriod.



22
23
24
25
# File 'lib/rubyfocus/review_period.rb', line 22

def initialize(size:0, unit: :months)
	self.size = size
	self.unit = unit
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/rubyfocus/review_period.rb', line 8

def size
  @size
end

#unitObject

Returns the value of attribute unit.



8
9
10
# File 'lib/rubyfocus/review_period.rb', line 8

def unit
  @unit
end

Class Method Details

.from_string(str) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rubyfocus/review_period.rb', line 12

def self.from_string(str)
	if str =~ /^[@~]?(\d+)([a-z])$/
		size = $1.to_i
		unit = {"d" => :days, "w" => :weeks, "m" => :months, "y" => :years}[$2]
		new(size: size, unit: unit)
	else
		raise ArgumentError, "Unrecognised review period format: \"#{str}\"."
	end
end

Instance Method Details

#short_unitObject



33
34
35
# File 'lib/rubyfocus/review_period.rb', line 33

def short_unit
	@short_unit ||= @unit.to_s[0]
end

#to_sObject Also known as: inspect, to_serial



37
38
39
# File 'lib/rubyfocus/review_period.rb', line 37

def to_s
	"#{size}#{short_unit}"
end