Class: LCCallNumber::Decimal

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

Overview

A generic “Decimal” part, where we keep the integer and fractional parts separate so we can construct a string more easily

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i, f = nil) ⇒ Decimal

Returns a new instance of Decimal.



74
75
76
77
# File 'lib/lc_callnumber/lcc.rb', line 74

def initialize(i, f=nil)
  @intpart = i
  @fractpart = f
end

Instance Attribute Details

#fractpartObject

Returns the value of attribute fractpart.



73
74
75
# File 'lib/lc_callnumber/lcc.rb', line 73

def fractpart
  @fractpart
end

#intpartObject

Returns the value of attribute intpart.



73
74
75
# File 'lib/lc_callnumber/lcc.rb', line 73

def intpart
  @intpart
end

Instance Method Details

#inspectObject



88
89
90
91
92
93
94
# File 'lib/lc_callnumber/lcc.rb', line 88

def inspect
  if fractpart
    "#{intpart}:#{fractpart}"
  else
    "#{intpart}"
  end
end

#to_numObject



79
80
81
# File 'lib/lc_callnumber/lcc.rb', line 79

def to_num
  fractpart ? "#{intpart}.#{fractpart}".to_f : intpart.to_i
end

#to_sObject



83
84
85
# File 'lib/lc_callnumber/lcc.rb', line 83

def to_s
  fractpart ? "#{intpart}.#{fractpart}" : intpart
end