Class: Dieses::Support::Ruler
- Inherits:
-
Object
- Object
- Dieses::Support::Ruler
- Defined in:
- lib/dieses/support/ruler.rb
Instance Attribute Summary collapse
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Class Method Summary collapse
Instance Method Summary collapse
- #division(length) ⇒ Object
- #even(length) ⇒ Object
-
#initialize(unit, multiple = 1) ⇒ Ruler
constructor
A new instance of Ruler.
- #major ⇒ Object
- #measure(n) ⇒ Object
Constructor Details
#initialize(unit, multiple = 1) ⇒ Ruler
Returns a new instance of Ruler.
17 18 19 20 |
# File 'lib/dieses/support/ruler.rb', line 17 def initialize(unit, multiple = 1) @unit = unit.to_f @multiple = multiple.to_f end |
Instance Attribute Details
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
15 16 17 |
# File 'lib/dieses/support/ruler.rb', line 15 def multiple @multiple end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
15 16 17 |
# File 'lib/dieses/support/ruler.rb', line 15 def unit @unit end |
Class Method Details
.call(unit, multiple = 1) ⇒ Object
6 7 8 |
# File 'lib/dieses/support/ruler.rb', line 6 def self.call(unit, multiple = 1) new unit, (multiple || 1) end |
.divide(unit:, multiple:, length:) ⇒ Object
10 11 12 13 |
# File 'lib/dieses/support/ruler.rb', line 10 def self.divide(unit:, multiple:, length:) ruler = new(unit, multiple) [ruler.division(length), ruler.even(length)] end |
Instance Method Details
#division(length) ⇒ Object
30 31 32 |
# File 'lib/dieses/support/ruler.rb', line 30 def division(length) (length / major).to_i.to_f end |
#even(length) ⇒ Object
26 27 28 |
# File 'lib/dieses/support/ruler.rb', line 26 def even(length) major * division(length) end |
#major ⇒ Object
22 23 24 |
# File 'lib/dieses/support/ruler.rb', line 22 def major @major ||= multiple * unit end |
#measure(n) ⇒ Object
34 35 36 |
# File 'lib/dieses/support/ruler.rb', line 34 def measure(n) n * unit end |