Class: Frequency

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

Defined Under Namespace

Classes: Undefined

Constant Summary collapse

FREQUENCIES =

Notes:

  • biweekly is ambiguous so I left it out

  • biennially != biannually

Values checked with Apple Dictionary Version 2.1.1 (80.1).

{
  "each second"   => 315_360_000,
  "each minute"   =>   5_256_000,
  "each hour"     =>      87_600,
  "each day"      =>       3_650,
  "each week"     =>         520,
  "each month"    =>         120,
  "each quarter"  =>          40,
  "each year"     =>          10,
  "hourly"        =>      87_600,
  "daily"         =>       3_650,
  "weekly"        =>         520,
  "fortnightly"   =>         260,
  "monthly"       =>         120,
  "quarterly"     =>          40,
  "biannually"    =>          20,
  "annual"        =>          10,
  "annually"      =>          10,
  "yearly"        =>          10,
  "biennial"      =>           5,
  "biennially"    =>           5,
  "quadrennial"   =>           2.5,
  "quadrennially" =>           2.5,
  "decade"        =>           1,
  "one time"      =>           0,
  "one-time"      =>           0,
  "other"         =>         nil,
  "unknown"       =>         nil,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Frequency

Returns a new instance of Frequency.



42
43
44
# File 'lib/frequency.rb', line 42

def initialize(string)
  self.plain_text = string ? string.downcase : ''
end

Instance Attribute Details

#plain_textObject

Returns the value of attribute plain_text.



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

def plain_text
  @plain_text
end

Instance Method Details

#<(other) ⇒ Object



54
55
56
# File 'lib/frequency.rb', line 54

def <(other)
  compare_safely(:<, other)
end

#<=(other) ⇒ Object



58
59
60
# File 'lib/frequency.rb', line 58

def <=(other)
  compare_safely(:<=, other)
end

#<=>(other) ⇒ Object



50
51
52
# File 'lib/frequency.rb', line 50

def <=>(other)
  compare_safely(:<=>, other)
end

#==(other) ⇒ Object



46
47
48
# File 'lib/frequency.rb', line 46

def ==(other)
  compare_safely(:==, other)
end

#>(other) ⇒ Object



62
63
64
# File 'lib/frequency.rb', line 62

def >(other)
  compare_safely(:>, other)
end

#>=(other) ⇒ Object



66
67
68
# File 'lib/frequency.rb', line 66

def >=(other)
  compare_safely(:>=, other)
end

#per_decadeObject



70
71
72
73
# File 'lib/frequency.rb', line 70

def per_decade
  value = FREQUENCIES[plain_text]
  value ? value : nil
end

#per_yearObject



75
76
77
78
# File 'lib/frequency.rb', line 75

def per_year
  value = FREQUENCIES[plain_text]
  value ? (value / 10.0) : nil
end

#valid?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/frequency.rb', line 80

def valid?
  FREQUENCIES.keys.include?(self.plain_text)
end