Class: LCCallNumber::Decimal
- Inherits:
-
Object
- Object
- LCCallNumber::Decimal
- 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
-
#fractpart ⇒ Object
Returns the value of attribute fractpart.
-
#intpart ⇒ Object
Returns the value of attribute intpart.
Instance Method Summary collapse
-
#initialize(i, f = nil) ⇒ Decimal
constructor
A new instance of Decimal.
- #inspect ⇒ Object
- #to_num ⇒ Object
- #to_s ⇒ Object
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
#fractpart ⇒ Object
Returns the value of attribute fractpart.
73 74 75 |
# File 'lib/lc_callnumber/lcc.rb', line 73 def fractpart @fractpart end |
#intpart ⇒ Object
Returns the value of attribute intpart.
73 74 75 |
# File 'lib/lc_callnumber/lcc.rb', line 73 def intpart @intpart end |
Instance Method Details
#inspect ⇒ Object
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_num ⇒ Object
79 80 81 |
# File 'lib/lc_callnumber/lcc.rb', line 79 def to_num fractpart ? "#{intpart}.#{fractpart}".to_f : intpart.to_i end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/lc_callnumber/lcc.rb', line 83 def to_s fractpart ? "#{intpart}.#{fractpart}" : intpart end |