Class: InsurancePolicy::Policy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(company, number, expires_on = nil) ⇒ Policy

Returns a new instance of Policy.



7
8
9
10
11
12
13
# File 'lib/insurance_policy/policy.rb', line 7

def initialize( company, number, expires_on=nil )
  @company    = company
  @number     = number
  @expires_on = expires_on

  self.freeze
end

Instance Attribute Details

#companyObject (readonly)

Returns the value of attribute company.



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

def company
  @company
end

#expires_onObject (readonly)

Returns the value of attribute expires_on.



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

def expires_on
  @expires_on
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#descriptionObject



19
20
21
22
# File 'lib/insurance_policy/policy.rb', line 19

def description
  [company, number].reject( &:blank? ).
                    join( ' Policy No.: ' )
end

#expired?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/insurance_policy/policy.rb', line 15

def expired?
  !expires_on.blank? && Time.zone.now >= expires_on
end

#to_sObject



24
25
26
# File 'lib/insurance_policy/policy.rb', line 24

def to_s
  description
end